Dominoes
Warning: If you are looking for pizza delivery you have come to the wrong page. Bloody Google (other search engines are available).
Take a box of dominoes give them a good shuffle and then arrange them in diverse orientations such that they form a rectangle with 7 rows of 8 columns. Make a tableau of the face values e.g.
05132231 05505246 43036620 06235126 11300245 21433466 64515414
Now torment your computer by making it identify where each domino is.
Do this for the above tableau and one of your own construction.
Extra credit:
How many ways are there to arrange dominoes in an 8x7 rectangle, first ignoring their values, then considering their values, and finally considering values but ignoring value symmetry, i.e. transposing 5 and 4.
F#
<lang fsharp> // Dominoes: Nigel Galloway. November 17th., 2021. let cP (n:seq<uint64 list * uint64>) g=seq{for y,n in n do for g in g do let l=n^^^g in if n+g=l then yield (g::y,l)} let rec fG n g=match g with h::t->fG(cP n h)t |_->fst(Seq.head n) let solve(N:int[])=let fG=let y=fG [([],0UL)]([for g in 0..47->((N.[g],N.[g+8]),(1UL<<<g)+(1UL<<<g+8))]@[for n in 0..6 do for g in n*8..n*8+6->((N.[g],N.[g+1]),(1UL<<<g)+(1UL<<<g+1))]
|>List.groupBy(fun((n,g),_)->(min n g,max n g))|>List.sort|>List.map(fun(_,n)->n|>List.map(fun(n,g)->g))) in (fun n g->if List.contains((1UL<<<n)+(1UL<<<g)) y then "+" else " ") N|>Array.chunkBySize 8|>Array.iteri(fun n g->let n=n*8 in [0..6]|>List.iter(fun y->printf $"%d{g.[y]}%s{fG(n+y)(n+y+1)}"); printfn $"%d{g.[7]}"; [0..7]|>List.iter(fun g->printf $"%s{fG(n+g)(n+g+8)} "); printfn "")
solve [|0;5;1;3;2;2;3;1;
0;5;5;0;5;2;4;6; 4;3;0;3;6;6;2;0; 0;6;2;3;5;1;2;6; 1;1;3;0;0;2;4;5; 2;1;4;3;3;4;6;6; 6;4;5;1;5;4;1;4|]
</lang>
- Output:
0+5 1+3 2 2+3 1 + + 0 5+5 0 5 2+4 6 + + 4 3 0 3 6+6 2 0 + + + + 0 6 2 3+5 1 2 6 + + 1 1 3 0+0 2 4 5 + + + + 2 1 4 3+3 4 6 6 + + 6 4+5 1+5 4 1+4
<lang fsharp> solve [|5;6;2;0;0;4;1;4;
3;6;1;3;0;4;2;2; 3;5;6;4;3;2;1;1; 3;5;1;1;3;0;0;5; 6;0;5;4;3;5;5;2; 4;4;1;3;6;6;0;2; 1;2;6;2;6;5;0;4|]
</lang>
- Output:
5+6 2+0 0 4 1+4 + + 3+6 1 3 0 4 2+2 + + 3 5 6 4 3+2 1 1 + + + + 3 5 1+1 3+0 0 5 6 0 5+4 3+5 5+2 + + 4 4 1+3 6 6+0 2 + + 1+2 6+2 6 5+0 4