Non-transitive dice: Difference between revisions
Content added Content deleted
(added Raku programming solution) |
(→{{header|Raku}}: generalization and a bit faster) |
||
Line 1,235: | Line 1,235: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
The 4 dice portion took around 28 minutes to run |
The 4 dice portion took around 17 (down from 28) minutes to run .. so it is not done yet. |
||
{{trans|Go}} |
{{trans|Go}} |
||
<lang perl6># 20201225 Raku programming solution |
<lang perl6># 20201225 Raku programming solution |
||
Line 1,241: | Line 1,241: | ||
my @dicepool = ^4 xx 4 ; |
my @dicepool = ^4 xx 4 ; |
||
sub |
sub FaceCombs(\N, @dp) { # for brevity, changed to use 0-based dice on input |
||
my @res = my @found = []; |
my @res = my @found = []; |
||
for [X] @ |
for [X] @dp { |
||
unless @found[ my \key = [+] ( |
unless @found[ my \key = [+] ( N «**« (N-1…0) ) Z* $_.sort ] { |
||
@found[key] = True; |
@found[key] = True; |
||
@res.push: $_ »+» 1 |
@res.push: $_ »+» 1 |
||
} |
} |
||
} |
} |
||
return @res |
return @res |
||
} |
} |
||
Line 1,258: | Line 1,258: | ||
} |
} |
||
sub |
sub findIntransitive(\N, \cs) { |
||
⚫ | |||
my @res = []; |
my @res = []; |
||
for [X] ^ |
for [X] ^+cs xx N -> @die { |
||
⚫ | |||
if so all ( cs[i] ⚖️ cs[j] , cs[j] ⚖️ cs[k] ) »==» -1 { |
|||
for @die[0..*].rotor(2 => -1) -> @p { |
|||
{ $skip = True and last } unless cs[@p[0]] ⚖️ cs[@p[1]] == -1 |
|||
} |
} |
||
next if $skip; |
|||
⚫ | |||
} |
} |
||
return @res |
return @res |
||
} |
} |
||
⚫ | |||
sub findIntransitive4(\cs) { |
|||
for 3, 4 { |
|||
my \c = +cs; |
|||
my @ |
my @output = findIntransitive($_, combs); |
||
⚫ | |||
for [X] ^c xx 4 -> (\i,\j,\k,\l) { |
|||
⚫ | |||
if so all ( cs[i] ⚖️ cs[j] , cs[j] ⚖️ cs[k], cs[k] ⚖️ cs[l] ) »==» -1 { |
|||
}</lang> |
|||
⚫ | |||
} |
|||
} |
|||
return @res |
|||
} |
|||
⚫ | |||
my @it3 = findIntransitive3(combs); |
|||
⚫ | |||
⚫ | |||
my @it4 := findIntransitive4(combs); |
|||
say +@it4, " ordered lists of 4 non-transitive dice found, namely:"; |
|||
.say for @it4;</lang> |
|||
{{out}} |
{{out}} |
||
<pre>Number of eligible 4-faced dice : 35 |
<pre>Number of eligible 4-faced dice : 35 |