Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov
Created September 6, 2016 21:15
Show Gist options
  • Select an option

  • Save v-kolesnikov/f592b4387b643af81cf6e6d0e065cd16 to your computer and use it in GitHub Desktop.

Select an option

Save v-kolesnikov/f592b4387b643af81cf6e6d0e065cd16 to your computer and use it in GitHub Desktop.
(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