-
Notifications
You must be signed in to change notification settings - Fork 8
Dz2 Sisin #11
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
base: main
Are you sure you want to change the base?
Dz2 Sisin #11
Conversation
# Conflicts: # .gitignore
@@ -1,4 +1,14 @@ | |||
(ns otus-02.homework.palindrome) | |||
(ns otus-02.homework.palindrome | |||
(:require [clojure.string :as s])) |
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.
это не ошибка, а скорее совет на будущее - одно или дву буквенные алиасы не рекомендуется использовать так как в будущем будет тяжело понять что это значит
в данном случае можно использовать string
в качестве алиаса
(defn common-child-length [first-string second-string] | ||
(cond | ||
(or (empty? first-string) (empty? second-string)) 0 | ||
(= (last first-string) (last second-string)) |
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.
хорошее решение
один вопрос - почему сравнение ведётся с конца строки используя last
?
кажется что можно сделать тоже самое но начать с начала используя first
в таком случае не прийдётся находить длину строки и вычитать единицу (- (count second-string) 1)
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.
Мне показалось, что это наилучшее решение с точки зрения динамического программирования, не нужно использовать лишнюю память.
Теперь, понимая особенности recur и вчерашнюю дискуссию по поводу last, понимаю, что оптимальней было создать структуру под матрицу значений и заполнять ее с начала
(filter some? | ||
(map alphabet |
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.
хороший вариант с сетом и фильтрацией
еще есть вариант с использованием clojure.string/replace
(s/replace (s/lower-case s-not-normal) #"[^a-z]" "")
регулярка #"[^a-z]"
сматчится на всё кроме букв
@@ -1,4 +1,9 @@ | |||
(ns otus-02.homework.pangram) | |||
(ns otus-02.homework.pangram | |||
(:require [otus-02.homework.palindrome :refer [normalize-str, alphabet]])) |
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.
запятые можно не ставить clojure их игнорирует, но если вам так удобнее то можно ставить
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-pangram [test-string]) | ||
|
||
(defn is-pangram [test-string] | ||
(= alphabet |
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 encode-string [input]) | ||
(defn mix [v r] |
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.
еще совет на будущее про имена - лучше использовать длинные понятные слова в качестве имен. через месяц уже обычно трудно вспомнить что это значило
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.
Спасибо за это замечание. Я с Вами согласен, но старался следовать соглашению о стиле https://github.com/bbatsov/clojure-style-guide#idiomatic-names
Возможно я его приватно истолковал
(defn encode-string [input] | ||
(let [n-input (normalize-str input) | ||
[r _] (size-field (count n-input)) | ||
v-input (partition r r (cycle " ") n-input) |
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.
отлично что использовали cycle
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.