0

Finding a combination in a table that matches a criteria

Given the following table of numbers

1 2 3 4 5 6 7 8 9 10 11 12 13
2 3 4 5 6 7 8 9 10 11 12 13 1
3 4 5 6 7 8 9 10 11 12 13 1 2
4 5 6 7 8 9 10 11 12 13 1 2 3
5 6 7 8 9 10 11 12 13 1 2 3 4
6 7 8 9 10 11 12 13 1 2 3 4 5

Is there a way to select a number from each column (13 numbers) in such a way that there are no repeating numbers, and the tally of selected numbers within each row is 5 rows of 2 and 1 row of 3?

I've been able to find patterns for 1, 2, 2, 2, 3, 3, for the amount of selected numbers in each row, but I can't find a way to do 2,2,2,2,2,and 3. Is it possible? If not, why?

An example selection where the tally of each row is 1,2,2,2,3,3 would be

2,6,7,8,5,9,10,13,11,12,3,4,1

Counting from the top row, there are 1, 2, 2, 2, 3, 3, selections in each row.

Thank you!

1 Answers1

0

I did an exhaustive brute search, and there is no solution. I have no explanation. I was suspected some parity explanation, but not sure at all.

The script that I used is a sql query. I have in entry one table IINT with integers from 1 to 13, and the sql-query is :

with rrr as ( 
select * from iint where i0 <= 6 ),

ccc as ( select * from iint where i0 <= 13 ) , tb as ( select rrr.i0 as rrr, ccc.i0 as ccc , case when rrr.i0+ccc.i0 <= 14 then rrr.i0+ccc.i0-1 else rrr.i0+ccc.i0-14 end as v from rrr, ccc order by 1,2 ) -- tb is the copy of original grid, 78 rows. , t1 as ( select C1.rrr as r1, c1.v as v1 , C2.rrr as r2, c2.v as v2 , C3.rrr as r3, c3.v as v3 , C4.rrr as r4, c4.v as v4 , C5.rrr as r5, c5.v as v5 , C6.rrr as r6, c6.v as v6 from tb c1, tb c2, tb c3 , tb c4 , tb c5 , tb c6 where c1.ccc = 1 and c2.ccc = 2 and c2.v <> c1.v and c3.ccc = 3 and c3.v <> c1.v and c3.v <> c2.v and c4.ccc = 4 and c4.v <> c1.v and c4.v <> c2.v and c4.v <> c3.v and c5.ccc = 5 and c5.v <> c1.v and c5.v <> c2.v and c5.v <> c3.v and c5.v <> c4.v and c6.ccc = 6 and c6.v <> c1.v and c6.v <> c2.v and c6.v <> c3.v and c6.v <> c4.v and c6.v <> c5.v ) -- t1 is a valid selection from columns 1 to 6 (each value v appears max once) , t2 as ( select C1.rrr as r7, c1.v as v1 , C2.rrr as r8, c2.v as v2 , C3.rrr as r9, c3.v as v3 , C4.rrr as r10, c4.v as v4 , C5.rrr as r11, c5.v as v5 , C6.rrr as r12, c6.v as v6 from tb c1, tb c2, tb c3 , tb c4 , tb c5 , tb c6 where c1.ccc = 7 and c2.ccc = 8 and c2.v <> c1.v and c3.ccc = 9 and c3.v <> c1.v and c3.v <> c2.v and c4.ccc = 10 and c4.v <> c1.v and c4.v <> c2.v and c4.v <> c3.v and c5.ccc = 11 and c5.v <> c1.v and c5.v <> c2.v and c5.v <> c3.v and c5.v <> c4.v and c6.ccc = 12 and c6.v <> c1.v and c6.v <> c2.v and c6.v <> c3.v and c6.v <> c4.v and c6.v <> c5.v ), -- t2 is a valid selection from columns 7 to 12 (each value v appears max once) w as ( SELECT T1., t2.r7, t2.v1 as V7, t2.r8, t2.v2 as V8, t2.r9, t2.v3 as V9, t2.r10, t2.v4 as V10, t2.r11, t2.v5 as V11, t2.r12, t2.v6 as V12 , tb.rrr as r13, tb.v as v13 , rownum as rn from t1, t2 , TB where t2.v1 <> t1.v1 and t2.v1 <> t1.v2 and t2.v1 <> t1.v3 and t2.v1 <> t1.v4 and t2.v1 <> t1.v5 and t2.v1 <> t1.v6 and t2.v2 <> t1.v1 and t2.v2 <> t1.v2 and t2.v2 <> t1.v3 and t2.v2 <> t1.v4 and t2.v2 <> t1.v5 and t2.v2 <> t1.v6 and t2.v3 <> t1.v1 and t2.v3 <> t1.v2 and t2.v3 <> t1.v3 and t2.v3 <> t1.v4 and t2.v3 <> t1.v5 and t2.v3 <> t1.v6 and t2.v4 <> t1.v1 and t2.v4 <> t1.v2 and t2.v4 <> t1.v3 and t2.v4 <> t1.v4 and t2.v4 <> t1.v5 and t2.v4 <> t1.v6 and t2.v5 <> t1.v1 and t2.v5 <> t1.v2 and t2.v5 <> t1.v3 and t2.v5 <> t1.v4 and t2.v5 <> t1.v5 and t2.v5 <> t1.v6 and t2.v6 <> t1.v1 and t2.v6 <> t1.v2 and t2.v6 <> t1.v3 and t2.v6 <> t1.v4 and t2.v6 <> t1.v5 and t2.v6 <> t1.v6 and tb.ccc=13 and tb.v not in ( t1.v1,t1.v2, t1.v3,t1.v4,t1.v5,t1.v6, t2.v1,t2.v2, t2.v3,t2.v4,t2.v5,t2.v6 ) ) -- w is the set of all valid solutions, rn is an id to identify each solution , x as ( select rn, r1 AS R0 from w union all select rn, r2 from w union all select rn, r3 from w union all select rn, r4 from w union all select rn, r5 from w union all select rn, r6 from w union all select rn, r7 from w union all select rn, r8 from w union all select rn, r9 from w union all select rn, r10 from w union all select rn, r11 from w union all select rn, r12 from w union all select rn, r13 from w ) -- this intermediate table x will be used to count the number of cells from each row. , y as ( SELECT rn , count ( case when r0=1 then 1 else null end ) as nb1, count ( case when r0=2 then 1 else null end ) as nb2, count ( case when r0=3 then 1 else null end ) as nb3, count ( case when r0=4 then 1 else null end ) as nb4, count ( case when r0=5 then 1 else null end ) as nb5, count ( case when r0=6 then 1 else null end ) as nb6 FROM X group by rn having count ( case when r0=1 then 1 else null end ) between 2 and 3 and count ( case when r0=2 then 1 else null end) between 2 and 3 and count ( case when r0=3 then 1 else null end) between 2 and 3 and count ( case when r0=4 then 1 else null end) between 2 and 3 and count ( case when r0=5 then 1 else null end) between 2 and 3 and count ( case when r0=6 then 1 else null end) between 2 and 3 ) -- y is the list of idenfifier rn that respect the constraint : 2 or 3 cells in each row. select w. from y, w where w.rn = y.rn -- For those solutions, display the value of all columns

Lourrran
  • 1,059
  • May I ask how you went about the exhaustive search or why you consider it exhaustive? I tried a ton of possible arrangements by hand over a whole day but didn't dare say it was exhaustive yet. – Thomas Liou Apr 25 '23 at 13:28
  • I have run a 'script' to search all solutions, and there was no solution at the end. – Lourrran Apr 25 '23 at 14:26
  • With same script, there are 8190 solutions with 1 number from row n°1 and 2 or 3 numbers in each other row. We have many symmetries in the pattern, 8190 seems a valid number as $8190=13 \times 10 \times 9 \times 7$. – Lourrran Apr 25 '23 at 14:33
  • would you mind sharing the script? – Thomas Liou Apr 25 '23 at 14:44
  • I have edited my answer, but SQL query is probably not what you wanted ! – Lourrran Apr 25 '23 at 14:55
  • Thank you so much! I know a bit of beginner sql so i'll try to figure it out! – Thomas Liou Apr 25 '23 at 15:07