Project Euler Problem 36

Ivar Thorson bio photo By Ivar Thorson

For problem 36, we need to find numbers that are palendromic in both base 2 and base 10. Thankfully, this is very simple to accomplish if we use the Java libraries to create the binary representations and also reuse a single function we wrote back in problem 4.

;; From Euler 4
(defn palindromic? [n] 
  (= (seq (str n)) (reverse (str n))))

(defn binary-palindromic? [n]
  (palindromic? (Integer/toBinaryString n)))

(defn euler-36 []
  (reduce + (filter #(and (palindromic? %)
                          (binary-palindromic? %))
                    (range 1 1000000))))

That was definitely too easy.