-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HW 02 Shamshurin Ivan #4
base: main
Are you sure you want to change the base?
Conversation
added recur palindrome function
1d5a154
to
0564097
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хорошо, отметил некоторые моменты в коде
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Модно, впервые вижу сравнение лонгов по ==
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если была здравая идея оптимизировать проверку, не создавая дубль перевернутой строки в памяти, то она полностью обесценилась созданием вектора и еще сабвекторов на каждой итерации...
(defn transform-string [s] | ||
(-> s | ||
(string/replace #"[,.-:;!?\"' ]" "") | ||
(string/lower-case))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Одиночные функции-макросы можно без скобочек
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Просто стиль - вы же выше умели в тред-макрос -> , зачем эти лишние леты и переменные?
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let [last-index (dec (count test-vec))
и не придется дублировать и писать лишние скобки, да еще и без тред-макросов )
|
||
(comment | ||
(is-pangram "The quick brown fox jumps over the lazy dog") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Идея хорошая. Только у меня выдает тру на вызове
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Одного реквайра с вектором векторов достаточно
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(trainling-spaces s col) == (str s (format (str "%" col "s") ""))
|
||
(defn transpose-string-v [v] | ||
(->> (map vec v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лишнее действие, строка и так имплементирует интерфейс последовательности
(count) | ||
(math/sqrt) | ||
(math/ceil) | ||
(int))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно без скобок
No description provided.