Find the missing permutation: Difference between revisions

m
→‎{{header|Phix}}: added a bit more explanation
(moved PHP below perl, addded Phix)
m (→‎{{header|Phix}}: added a bit more explanation)
Line 1,490:
r = sq_sub(max(r)+'A',r)
puts(1,r&'\n')
-- based on the notion that missing = sum(full)-sum(partial) would be true,
-- and that sum(full) would be like {M,M,M,M} rather than a mix of numbers.
-- the final step is equivalent to eg {1528,1530,1531,1529}
-- max-r[i] -> { 3, 1, 0, 2}
-- to chars -> { D, B, A, C}
-- (but obviously allboth done in one stepline)
 
-- 2: the xor trick
Line 1,501 ⟶ 1,503:
end for
puts(1,r&'\n')
-- (relies on the missing chars being present an odd number of times, non-missing chars an even number of times)
 
-- 3: find least frequent letters
Line 1,512 ⟶ 1,515:
end for
puts(1,r&'\n')
-- (relies on the assumption that a full set would have each letter occurring the same number of times in each position)
 
-- 4: test all permutations
Line 1,518 ⟶ 1,522:
if not find(r,perms) then exit end if
end for
puts(1,r&'\n')</lang>
-- (relies on brute force(!) - but this is the only method that could be made to cope with >1 omission)</lang>
{{out}}
<pre>
7,820

edits