Latin Squares in reduced form/Randomizing using Jacobson and Matthews’ Technique: Difference between revisions
Latin Squares in reduced form/Randomizing using Jacobson and Matthews’ Technique (view source)
Revision as of 16:16, 30 July 2021
, 2 years ago→{{header|Raku}}: fix oversight in squares generation
(added Raku programming solution) |
(→{{header|Raku}}: fix oversight in squares generation) |
||
Line 1,337:
{{trans|Go}}
<lang perl6># 20210729 Raku programming solution
#!/usr/bin/env raku
sub makeCube(\from, Int \n) {
Line 1,345 ⟶ 1,347:
}
sub shuffleCube(@c
my ($rx, $ry, $rz); my \n = +@c; my Bool \proper = $ = True;
Line 1,370 ⟶ 1,372:
proper = False
}
}
Line 1,415 ⟶ 1,416:
@c = makeCube(@in, 4);
for ^10_000 {
}
for %freq.kv -> $k, $v {
Line 1,429 ⟶ 1,428:
%freq = ();
@c = makeCube(@in, 5);
for ^10_000 {
}
for %freq.values.kv -> $i, $j { printf "%2d(%3d)%s", $i+1, $j, ' ' }
Line 1,439 ⟶ 1,436:
say "\n\nPart 3: 750 latin squares of order 42, showing the last one:\n";
@c = makeCube([], 42); # (1..42).pick(*)
say "\nPart 4:
@c = makeCube([], 256);▼
my $snapshot = now;
▲@c = makeCube([], 256);
say "Generated in { now - $snapshot } seconds."
</lang>
Line 1,453 ⟶ 1,447:
<pre>
Part 1: 10,000 latin Squares of order 4 in reduced form:
1 2 3 4▼
3 4 1 2▼
1 2 3 4
Line 1,459 ⟶ 1,460:
4 3 2 1
Occurs
1 2 3 4
2
3 4 1 2
4
Occurs
1 2 3 4
Line 1,473 ⟶ 1,474:
4 3 1 2
Occurs
▲1 2 3 4
▲2 3 4 1
▲3 4 1 2
▲4 1 2 3
▲Occurs 2518 times.
Part 2: 10,000 latin Squares of order 5 in reduced form:
1(
Part 3: 750 latin squares of order 42, showing the last one:
1 22 2
38
Part 4:
Generated in
</pre>
|