Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created October 4, 2012 21:44
Show Gist options
  • Save amalloy/3836677 to your computer and use it in GitHub Desktop.
Save amalloy/3836677 to your computer and use it in GitHub Desktop.
(defn longest-palindrome [s]
(let [palindrome? #(= (seq %) (reverse %))
slice-all (fn [s] (mapcat #(partition % 1 s)
(map first
(take-while seq
(iterate rest
(range (count s) 1 -1))))))]
(first (filter palindrome? (slice-all s)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment