Find the missing permutation: Difference between revisions
Content deleted Content added
→Python:Counting lowest frequency character at each position: functional: Added an XOR variant. |
→Haskell :: Folding XOR over the list of permutations: Added XOR variant. |
||
Line 1,275: | Line 1,275: | ||
{{Out}} |
{{Out}} |
||
<pre>"DBAC"</pre> |
<pre>"DBAC"</pre> |
||
====Folding XOR over the list of permutations==== |
|||
Surfacing the missing bits: |
|||
{{Trans|JavaScript}} |
|||
{{Trans|Python}} |
|||
<lang haskell>import Data.Char (chr, ord) |
|||
import Data.Bits (xor) |
|||
missingPerm :: [String] -> String |
|||
missingPerm = fmap chr . foldr (zipWith xor . fmap ord) [0, 0, 0, 0] |
|||
deficientPermsList :: [String] |
|||
deficientPermsList = |
|||
[ "ABCD" |
|||
, "CABD" |
|||
, "ACDB" |
|||
, "DACB" |
|||
, "BCDA" |
|||
, "ACBD" |
|||
, "ADCB" |
|||
, "CDAB" |
|||
, "DABC" |
|||
, "BCAD" |
|||
, "CADB" |
|||
, "CDBA" |
|||
, "CBAD" |
|||
, "ABDC" |
|||
, "ADBC" |
|||
, "BDCA" |
|||
, "DCBA" |
|||
, "BACD" |
|||
, "BADC" |
|||
, "BDAC" |
|||
, "CBDA" |
|||
, "DBCA" |
|||
, "DCAB" |
|||
] |
|||
main :: IO () |
|||
main = putStrLn $ missingPerm deficientPermsList</lang> |
|||
{{Out}} |
|||
<pre>DBAC</pre> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |