Skip to content

Instantly share code, notes, and snippets.

@knjname
Created January 3, 2014 13:49
Show Gist options
  • Select an option

  • Save knjname/8238155 to your computer and use it in GitHub Desktop.

Select an option

Save knjname/8238155 to your computer and use it in GitHub Desktop.
(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