Non-transitive dice: Difference between revisions
→{{header|Raku}}: minor efficiency tweaks
(→{{header|Raku}}: generalization and a bit faster) |
Thundergnat (talk | contribs) (→{{header|Raku}}: minor efficiency tweaks) |
||
Line 1,242:
sub FaceCombs(\N, @dp) { # for brevity, changed to use 0-based dice on input
my @res = my @found = [];
for [X] @dp {
unless @found[ my \key = [+] ( N «**« (N-1…0) ) Z*
@found[key] = True;
@res.push: $_ »+» 1
}
}
}
sub infix:<⚖️>(@x, @y) {
my
+(b{Less} <=> b{More})
}
sub findIntransitive(\N, \cs) {
my @res = [];
race for [X] ^+cs xx N -> @die {
my $skip = False;
for @die[0..*].rotor(2 => -1) -> @p {
{ $skip = True and last } unless cs[@p[0]] ⚖️ cs[@p[1]] == -1
}
next if $skip;
if cs[@die[0]] ⚖️ cs[@die[*-1]] == 1 { @res.push: [ cs[@die[0..*]] ] }
}
}
say "Number of eligible 4-faced dice : ", +(my \combs = FaceCombs(4,@dicepool));
for 3, 4 {
my @output = findIntransitive($_, combs);
say +@output, " ordered lists of $_ non-transitive dice found, namely:";
.say for @output;
}</lang>
{{out}}
|