Find the missing permutation: Difference between revisions

m
→‎Python:Folding XOR over the set of strings: (:Pruned out some scaffolding)
m (→‎Python:Folding XOR over the set of strings: (:Pruned out some scaffolding))
Line 2,591:
 
from functools import reduce
from operator import xor
 
 
print(''.join([
# main :: IO ()
chr(i) for i in reduce(
def main():
lambda a, s: map(xor, a, codes(s)),
'''Missing bits surfaced by folding XOR
over the set of strings. xor, a,
return [ord(c) for c in list(s)]
'''
), [
 
'BADCABCD', 'BDACCABD', 'CBDAACDB', 'DBCADACB', 'DCABBCDA', 'ACBD',
xs = [
'ABCDADCB', 'CABDCDAB', 'ACDBDABC', 'DACBBCAD', 'BCDACADB', 'ACBDCDBA',
'ADCBCBAD', 'CDABABDC', 'DABCADBC', 'BCADBDCA', 'CADBDCBA', 'CDBABACD',
'CBAD', 'ABDCBADC', 'ADBCBDAC', 'BDCACBDA', 'DCBADBCA', 'BACDDCAB',
xs[1:],
'BADC', 'BDAC', 'CBDA', 'DBCA', 'DCAB'
[0, 0, 0, 0]
print(''.join([)
main(]))</lang>
chr(i) for i in reduce(
lambda a, s: map(xor, a, codes(s)),
xs[1:],
codes(xs[0])
)
]))
 
 
# ------------------------ GENERIC -------------------------
 
# codes :: String -> [Int]
def codes(s):
'''The ordinal code of each character in s.
'''
return [ord(c) for c in list(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__':
main()</lang>
{{Out}}
<pre>DBAC</pre>
9,655

edits