Created
February 23, 2010 15:26
-
-
Save hroi/312294 to your computer and use it in GitHub Desktop.
This file contains 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
; 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