Created
October 4, 2012 22:50
-
-
Save RobertARandolph/3836958 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
(defn longest-palindrome [s] | |
(let [palindrome? #(= (seq %) (reverse %)) | |
slice-all (fn [s] (mapcat #(partition % 1 s) (mapcat list (range (count s) 1 -1))))] | |
(some palindrome? (slice-all s)))) | |
;; or to return palindrome | |
(defn longest-palindrome [s] | |
(let [palindrome? #(= (seq %) (reverse %)) | |
slice-all (fn [s] (mapcat #(partition % 1 s) (mapcat list (range (count s) 1 -1))))] | |
(first (filter palindrome? (slice-all s))))) |
Ignore that last comment :|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get actual palindrome:
(defn longest-palindrome [s](let [palindrome? #%28= %28seq %%29 %28reverse %%29%29
slice-all %28fn [s] %28mapcat #%28partition % 1 s%29 %28mapcat list %28range %28count s%29 1 -1%29%29%29%29]
%28first %28filter palindrome? %28slice-all s%29%29%29))