Skip to content

Instantly share code, notes, and snippets.

@hroi
Created February 23, 2010 15:26
Show Gist options
  • Save hroi/312294 to your computer and use it in GitHub Desktop.
Save hroi/312294 to your computer and use it in GitHub Desktop.
; Problem 4
; A palindromic number reads the same both ways. The largest
; palindrome made from the product of two 2-digit numbers
; is 9009 = 91 99.
;
; Find the largest palindrome made from the product of two 3-digit numbers.
(defn palindromic? [x]
(let [strx (str x)]
(= (seq strx) (reverse strx))))
(def pals
(filter #(not (empty? %))
(for [x (range 100 1000)]
(filter #(palindromic? (last %))
(for [y (range x 1000)]
[x y (* x y)])))))
(def largest
(last
(first (sort #(> (last %1) (last %2)) (map last pals)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment