Conversation
added recur palindrome function
1d5a154 to
0564097
Compare
Ivana-
left a comment
There was a problem hiding this comment.
Хорошо, отметил некоторые моменты в коде
| (let [go-next (= (get test-vec 0) (get test-vec (dec (count test-vec))))] | ||
| (cond | ||
| (empty? test-vec) true | ||
| (== (count test-vec) 1) true |
There was a problem hiding this comment.
Модно, впервые вижу сравнение лонгов по ==
| (empty? test-vec) true | ||
| (== (count test-vec) 1) true | ||
| (not go-next) false | ||
| :else (recur (subvec test-vec 1 (dec (count test-vec))))))) |
There was a problem hiding this comment.
Если была здравая идея оптимизировать проверку, не создавая дубль перевернутой строки в памяти, то она полностью обесценилась созданием вектора и еще сабвекторов на каждой итерации...
| (defn transform-string [s] | ||
| (-> s | ||
| (string/replace #"[,.-:;!?\"' ]" "") | ||
| (string/lower-case))) |
There was a problem hiding this comment.
Одиночные функции-макросы можно без скобочек
| (defn is-palindrome [test-string] | ||
| (let [s (transform-string test-string) | ||
| s-vec (vec s)] | ||
| (recur-palindrom s-vec))) |
There was a problem hiding this comment.
Просто стиль - вы же выше умели в тред-макрос -> , зачем эти лишние леты и переменные?
(defn is-palindrome [s] (-> s transform-string vec recur-palindrom))
или если выпендриться, тогда уж
(def is-palindrome (comp recur-palindrom vec transform-string))
|
|
||
| (defn is-palindrome [test-string]) | ||
| (defn recur-palindrom [test-vec] | ||
| (let [go-next (= (get test-vec 0) (get test-vec (dec (count test-vec))))] |
There was a problem hiding this comment.
let [last-index (dec (count test-vec))
и не придется дублировать и писать лишние скобки, да еще и без тред-макросов )
| (== alphabet-count))) | ||
|
|
||
| (comment | ||
| (is-pangram "The quick brown fox jumps over the lazy dog") |
There was a problem hiding this comment.
Идея хорошая. Только у меня выдает тру на вызове
(is-pangram "abcdefgh!№%^*()&^$+_<>,./{}@#$~|")
| (ns otus-02.homework.square-code | ||
| (:require [clojure.string :as string]) | ||
| (:require [clojure.math :as math]) | ||
| (:require [otus-02.homework.palindrome :as pal])) |
There was a problem hiding this comment.
Одного реквайра с вектором векторов достаточно
| (defn split-for-encode [col initial s] | ||
| (cond | ||
| (empty? s) initial | ||
| (<= (count s) col) (conj initial (trainling-spaces s col)) |
There was a problem hiding this comment.
(trainling-spaces s col) == (str s (format (str "%" col "s") ""))
| :else (recur col (conj initial (subs s 0 col)) (subs s col)))) | ||
|
|
||
| (defn transpose-string-v [v] | ||
| (->> (map vec v) |
There was a problem hiding this comment.
Лишнее действие, строка и так имплементирует интерфейс последовательности
| (count) | ||
| (math/sqrt) | ||
| (math/ceil) | ||
| (int))) |
No description provided.