Skip to content

Instantly share code, notes, and snippets.

@mordaha
Created January 16, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mordaha/4aa8e5b5c2132f50b929fc92c877bd76 to your computer and use it in GitHub Desktop.
Save mordaha/4aa8e5b5c2132f50b929fc92c877bd76 to your computer and use it in GitHub Desktop.
;; ---------------------------------------------
(def sss "qwetyadddaaqweddddrtjjashdqwertyuiopoiuytrewqkjfhkasjhsajkhfy")
(defn checkCountAt
[s cnt index]
(let [s1 (subs s index (+ index cnt))
s2 (clojure.string/reverse s1)]
(= s1 s2)))
(defn findThree
[s]
(let [j (- (count s) 3)]
(loop [i (- (count s) 3)
indexes []]
(if (= i 0)
indexes
(if (checkCountAt s 3 i)
(recur (dec i) (conj indexes (inc i)))
(recur (dec i) indexes))))))
(defn findMaxAt
[s index]
(loop [i index
j (inc index)
maxP ""]
(let [s1 (subs s i j)
s2 (clojure.string/reverse s1)]
(if (and (> i 0) (= s1 s2))
(recur (dec i) (inc j) s1)
maxP))))
(defn findMaxThree
[s]
(map (fn [index] (findMaxAt s index)) (findThree s)))
(findMaxThree sss) ;; ("qwertyuiopoiuytrewq" "ddd" "ddd" "addda")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment