Created
January 3, 2014 13:49
-
-
Save knjname/8238155 to your computer and use it in GitHub Desktop.
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
| (defn palindromic? [n] | |
| (let [straight (seq (str n)) | |
| reversed (reverse straight)] | |
| (= straight reversed))) | |
| (palindromic? 9009) ; true | |
| (palindromic? 909) ; true | |
| (palindromic? 1023) ; false | |
| (defn combination [seq1 seq2] | |
| (for [x seq1 | |
| y seq2] | |
| [x y])) | |
| (defmacro combination [& seqs] | |
| (let [seq-var (map (fn [x] [(gensym) x]) seqs)] | |
| `(for [~@(apply concat seq-var)] | |
| [~@(->> seq-var | |
| (map #(first %)) | |
| flatten )]))) | |
| (combination [1 2 3] [4 5 6] [7 8 9 10]) | |
| (println | |
| (let [search-range (range 100 1000) | |
| all-combinations (combination search-range search-range)] | |
| (->> all-combinations | |
| (map (fn [[a b]] (* a b))) | |
| (filter palindromic?) | |
| (apply max)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment