Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion otus-01/src/otus/homework.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
(ns otus.homework)


(defn solution "Add your solution as fuction body here" [])
(defn solution
"Add your solution as function body here"
[]
(double
(/
(+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7)))))

43 changes: 37 additions & 6 deletions otus-02/src/otus_02/homework/common_child.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(ns otus-02.homework.common-child)
(ns otus-02.homework.common-child
(:require [clojure.string :as s]
[clojure.set :refer [intersection]]))


;; Строка называется потомком другой строки,
Expand All @@ -15,8 +17,37 @@

;; Еще пример HARRY и SALLY. Ответ будет - 2, так как общий элемент у них AY


(defn common-child-length [first-string second-string])



(defn combinations
"Ищем все возможные комбинации потомков в сторке с учетом порядка следования букв"
[letters]
(loop [result nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот тут не совсем понятка задумка. зачем тут loop? в теле нет вызова recur значит итерации не будет. вместо этого используется рекурсия

rest-result letters]
(if (empty? rest-result)
#{result}
(let [current (first rest-result)
next-result (conj result current)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это похоже не используется?

combinations-without (combinations (rest rest-result))
combinations-with (mapv #(str current %) combinations-without)]
(set (concat combinations-with (combinations (rest rest-result))))))))

(defn delete-not-repeat-letter
"Удаляем не повторяющиеся буквы в двух строках"
[first-string second-string]
(filterv identity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter identity обычно можно заменить на вызов функции remove

(map (fn [x]
(if (s/includes? second-string x)
x)) first-string)))

(defn common-child-length
"Вычисляем максимального потомка"
[first-string second-string]
(let [s1 (re-seq #"[\w+]" first-string)
s2 (re-seq #"[\w+]" second-string)
s1-not-repeat (delete-not-repeat-letter s1 s2)
s2-not-repeat (delete-not-repeat-letter s2 s1)]
(reduce max
(map count
(some-> (intersection (combinations s1-not-repeat) (combinations s2-not-repeat)))))))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а для чего используется some-> ? кажется лишним


;;(time (common-child-length "HARRY" "SALLY"))
;;=> "Elapsed time: 0.132041 msecs"
9 changes: 7 additions & 2 deletions otus-02/src/otus_02/homework/palindrome.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
(:require [clojure.string :as string]))


(defn is-palindrome [test-string])

(defn is-palindrome
[test-string]
(as-> test-string p

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хороший подход. решение верное 👍
Вы заметили что переменная p всё время выступает в качестве последнего аргумента? Можно воспользоваться ->> макросом! он как раз помещает результат в нужное место

(re-seq #"[\w+]" p)
(string/join "" p)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

такой вопрос - а зачем джойнить список обратно в строку? списки и вектора можно сравнивать напрямую

(string/lower-case p)
(= (string/reverse p) p)))
10 changes: 8 additions & 2 deletions otus-02/src/otus_02/homework/pangram.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
(:require [clojure.string :as string]))


(defn is-pangram [test-string])

(defn is-pangram
[test-string]
(as-> test-string p

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как и в примере с палиндромом можно брать ->>

(string/lower-case p)
(re-seq #"[\w+]" p)
(set p)
(string/join "" p)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут джойн в строку тоже выглядит как лишняя операция

(= (count p) 26)))