Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created March 16, 2011 17:14
Show Gist options
  • Save swannodette/872860 to your computer and use it in GitHub Desktop.
Save swannodette/872860 to your computer and use it in GitHub Desktop.
(defn palindrome-o [x]
(exist [a b c d]
(digit-o a) (digit-o b) (digit-o c) (digit-o d)
(nonrel/project [a b c d]
(== x (* (+ (* 10 a) b)
(+ (* 10 c) d)))
(nonrel/project [x]
(== (> x 0) true)
(== (>= x 100) true)
(== (mod (int (/ x 1000)) 10)
(mod (int (/ x 1)) 10))
(== (mod (int (/ x 100)) 10)
(mod (int (/ x 10)) 10))))))
(defn palindrome []
(let [r (range 9)]
(for [a r b r
c r d r
:let [x (* (+ (* 10 a) b)
(+ (* 10 c) d))]
:when (and (> x 0)
(>= x 100)
(= (mod (int (/ x 1000)) 10)
(mod (int (/ x 1)) 10))
(= (mod (int (/ x 100)) 10)
(mod (int (/ x 10)) 10)))]
x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment