Created
October 13, 2011 15:15
-
-
Save candera/1284476 to your computer and use it in GitHub Desktop.
Solve a 3x3 grid puzzle: all rows must add to 15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.math.combinatorics) | |
(def possible-answers (permutations (range 1 10))) | |
(defn sum-els [coll a b c] | |
(+ (nth coll a) | |
(nth coll b) | |
(nth coll c))) | |
(defn right-answer [coll] | |
(= 15 | |
(sum-els coll 0 1 2) | |
(sum-els coll 3 4 5) | |
(sum-els coll 6 7 8) | |
(sum-els coll 0 3 6) | |
(sum-els coll 1 4 7) | |
(sum-els coll 2 5 8) | |
(sum-els coll 0 4 8) | |
(sum-els coll 2 4 6))) | |
(def answers (filter right-answer possible-answers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment