Created
January 16, 2018 11:28
-
-
Save mordaha/4aa8e5b5c2132f50b929fc92c877bd76 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
;; --------------------------------------------- | |
(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