-
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
Changes from all commits
c49d7af
bae2c03
0cb5b6e
5db689d
4ea4614
fdc8e39
9fbbfdd
76af3b7
bd5c8bb
7043672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ pom.xml.asc | |
.hg/ | ||
.clj-kondo | ||
.calva | ||
.lsp | ||
.lsp | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. это не ошибка, а скорее совет на будущее - одно или дву буквенные алиасы не рекомендуется использовать так как в будущем будет тяжело понять что это значит |
||
|
||
(def alphabet (set "abcdefghijklmnopqrstuvwxyz")) | ||
|
||
(defn normalize-str [s-not-normal] | ||
(filter some? | ||
(map alphabet | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. хороший вариант с сетом и фильтрацией |
||
(s/lower-case s-not-normal)))) | ||
|
||
(defn is-palindrome [test-string] | ||
(= (normalize-str test-string) | ||
(normalize-str (s/reverse test-string)))) | ||
|
||
(defn is-palindrome [test-string]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
(set (normalize-str test-string)))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
(ns otus-02.homework.square-code) | ||
(ns otus-02.homework.square-code | ||
(:require [otus-02.homework.palindrome :refer [normalize-str]] | ||
[clojure.string :as s])) | ||
|
||
;; Реализовать классический метод составления секретных сообщений, называемый `square code`. | ||
;; Выведите закодированную версию полученного текста. | ||
|
@@ -48,9 +50,38 @@ | |
"aohghn " | ||
"sseoau " | ||
|
||
(defn size-field [len-str] | ||
(let [x (int (Math/sqrt len-str))] | ||
(cond | ||
(= len-str (* x x)) [x x] | ||
(<= len-str (* x (inc x))) [(inc x) x] | ||
:else [(inc x) (inc x)]))) | ||
|
||
|
||
|
||
(defn encode-string [input]) | ||
(defn mix [v r] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Спасибо за это замечание. Я с Вами согласен, но старался следовать соглашению о стиле https://github.com/bbatsov/clojure-style-guide#idiomatic-names |
||
(for [i (range r)] | ||
(map #(nth % i "") v))) | ||
|
||
(defn l->str [l] | ||
(map #(apply str %) l) | ||
) | ||
|
||
(defn decode-string [input]) | ||
(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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Буду честен, просто утянул с интернета. Мне нужна была бесконечная последовательность пробелов. :) |
||
l-mix (mix v-input r) | ||
s-mix (l->str l-mix)] | ||
(s/join " " s-mix))) | ||
|
||
(encode-string "If man was meant to stay on the ground, god would have given us roots.") | ||
|
||
(defn decode-string [input] | ||
(let [l-input (s/split input #" ") | ||
r (count (get l-input 0)) | ||
v-input (mix l-input r) | ||
s-input (l->str v-input)] | ||
(apply str (normalize-str (s/join s-input))))) | ||
|
||
(decode-string "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ") |
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, понимаю, что оптимальней было создать структуру под матрицу значений и заполнять ее с начала