Find the missing permutation: Difference between revisions

→‎{{header|Clojure}}: added alternate implementation; update library name in first impl
(→‎{{header|Clojure}}: added alternate implementation; update library name in first impl)
Line 272:
=={{header|Clojure}}==
<lang clojure>
(use 'clojure.contribmath.combinatorics)
(use 'clojure.set)
 
Line 279:
(def missing (difference s1 given))
</lang>
Here's a version based on the hint in the description. ''freqs'' is a sequence of letter frequency maps, one for each column. There should be 6 of each letter in each column, so we look for the one with 5.
<lang clojure>(def abcds ["ABCD" "CABD" "ACDB" "DACB" "BCDA" "ACBD" "ADCB" "CDAB"
"DABC" "BCAD" "CADB" "CDBA" "CBAD" "ABDC" "ADBC" "BDCA"
"DCBA" "BACD" "BADC" "BDAC" "CBDA" "DBCA" "DCAB"])
(def freqs (->> abcds (apply map vector) (map frequencies)))
 
(defn v->k [fqmap v] (->> fqmap (filter #(-> % second (= v))) ffirst))
 
(->> freqs (map #(v->k % 5)) (apply str) println)</lang>
 
=={{header|CoffeeScript}}==
Anonymous user