Find the missing permutation: Difference between revisions
Content added Content deleted
(→Haskell :: Folding XOR over the list of permutations: Added XOR variant.) |
m (→Python:Folding XOR over the set of strings: (:Pruned out some scaffolding)) |
||
Line 2,591: | Line 2,591: | ||
from functools import reduce |
from functools import reduce |
||
from operator import xor |
|||
print(''.join([ |
|||
# main :: IO () |
|||
⚫ | |||
def main(): |
|||
⚫ | |||
'''Missing bits surfaced by folding XOR |
|||
xor, a, |
|||
⚫ | |||
''' |
|||
⚫ | |||
⚫ | |||
xs = [ |
|||
' |
'ADCB', 'CDAB', 'DABC', 'BCAD', 'CADB', 'CDBA', |
||
' |
'CBAD', 'ABDC', 'ADBC', 'BDCA', 'DCBA', 'BACD', |
||
'BADC', 'BDAC', 'CBDA', 'DBCA', 'DCAB' |
|||
⚫ | |||
⚫ | |||
] |
[0, 0, 0, 0] |
||
) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
codes(xs[0]) |
|||
⚫ | |||
])) |
|||
# ------------------------ GENERIC ------------------------- |
|||
# codes :: String -> [Int] |
|||
def codes(s): |
|||
'''The ordinal code of each character in s. |
|||
''' |
|||
⚫ | |||
# xor :: (Int, Int) -> Int |
|||
def xor(a, b): |
|||
'''Exclusive OR over the bits of integers a and b. |
|||
''' |
|||
return a ^ b |
|||
# MAIN --- |
|||
if __name__ == '__main__': |
|||
⚫ | |||
{{Out}} |
{{Out}} |
||
<pre>DBAC</pre> |
<pre>DBAC</pre> |