Jump to content

Random Latin squares: Difference between revisions

no edit summary
(Added solution for Action!)
No edit summary
Line 1,343:
4 8 9 5 0 6 1 2 3 7
</pre>
 
=={{header|J}}==
<lang j>rls=: 3 : 0
s=. ?~ y NB. "deal" y unique integers from 0 to y
for_ijk. i.<:y do.
NB. deal a new row. subtract it from all previous rows
NB. if you get a 0, some column has a matching integer, deal again
whilst. 0 = */ */ s -"1 r do.
r=. ?~ y
end.
s=. s ,,: r NB. "laminate" successful row to the square
end.
)
</lang>
{{out}}
<pre> rls 5
4 0 1 2 3
3 1 4 0 2
2 3 0 4 1
0 2 3 1 4
1 4 2 3 0
rls 5
0 4 2 1 3
4 1 3 2 0
1 0 4 3 2
2 3 1 0 4
3 2 0 4 1</pre>
 
=={{header|Java}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.