Created
September 6, 2016 21:15
-
-
Save v-kolesnikov/f592b4387b643af81cf6e6d0e065cd16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (ns sicp.extra.hexlet | |
| (:require [clojure.string :as s])) | |
| (defn solution | |
| [s] | |
| (let [substrings (fn [i] (map (partial subs (str s) i) (range (inc i) (-> (str s) count inc)))) | |
| palindrome? (fn [s] (= (s/reverse s) s))] | |
| (->> (str s) | |
| (count) | |
| (range 0) | |
| (mapcat substrings) | |
| (filter palindrome?) | |
| (apply max-key count)))) | |
| (assert (= "dhfdkjfffhhfffjkdfhd" (solution "afbbbfjdjklgdfdhfdkjfffhhfffjkdfhdhkyejejfjkd"))) | |
| (assert (= "racecar" (solution "bartarcarracecarbartar"))) | |
| (assert (= "46264" (solution "3.1415926535897932384626433832795028841971"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment