Non-transitive dice: Difference between revisions
→{{header|Phix}}: optimise: [k+2..$]:=l and cache
(Add Factor) |
(→{{header|Phix}}: optimise: [k+2..$]:=l and cache) |
||
Line 307:
function find_non_trans(sequence dice, integer n=3)
integer l = length(dice), sk, sk1, c
sequence set = repeat(1,n), -- (indexes to dice)
cache = repeat(repeat(-2,l),l),
res = {}
while true do
bool valid = true
for k=1 to n-1 do
sk1 = set[k+1]
c = cache[sk][sk1]
if c=-2 then
c = cmpd(dice[sk],dice[sk1])
cache[sk][sk1] = c
end if
if c!=-1 then
valid = false
set[k+2..$] = l
exit
end if
end for
if valid
sk1 = set[$]
c = cache[sk][sk1]
if c=-2 then
c = cmpd(dice[sk],dice[sk1])
cache[sk][sk1] = c
end if
if c=+1 then
res = append(res,set)
end if
end if
-- find rightmost incrementable die index
|