From f8046a8b3cfba4cd8d44a9f98d6a3efebc772dc1 Mon Sep 17 00:00:00 2001 From: kosbar Date: Thu, 11 Jul 2024 14:32:45 +0500 Subject: [PATCH 1/3] Homework for lesson Otus_01 --- otus-01/src/otus/homework.clj | 3 ++- otus-01/test/otus/homework_test.clj | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/otus-01/src/otus/homework.clj b/otus-01/src/otus/homework.clj index 82c8e9d..6a75ff5 100644 --- a/otus-01/src/otus/homework.clj +++ b/otus-01/src/otus/homework.clj @@ -1,5 +1,6 @@ (ns otus.homework) -(defn solution "Add your solution as fuction body here" []) +(defn solution "Add your solution as fuction body here" [] + (/ (+ 5.0 4.0 (- 2.0 (- 3.0 (+ 6.0 (/ 4.0 5.0))))) (* 3.0 (- 6.0 2.0) (- 2.0 7.0)))) diff --git a/otus-01/test/otus/homework_test.clj b/otus-01/test/otus/homework_test.clj index 9cc096f..50bb99d 100644 --- a/otus-01/test/otus/homework_test.clj +++ b/otus-01/test/otus/homework_test.clj @@ -4,5 +4,5 @@ (deftest s-expression-solution-test - (is (= (sut/solution) -0.2466666666666667) + (is (= (sut/solution) -0.24666666666666667) "solution function returns a correct answer")) From 2156d27c50642f53f565dd4e5b5608f8e5d99f9f Mon Sep 17 00:00:00 2001 From: kosbar Date: Thu, 11 Jul 2024 15:40:25 +0500 Subject: [PATCH 2/3] Homework for lesson Otus-02 --- otus-02/src/otus_02/homework/palindrome.clj | 11 ++++++++--- otus-02/src/otus_02/homework/pangram.clj | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/otus-02/src/otus_02/homework/palindrome.clj b/otus-02/src/otus_02/homework/palindrome.clj index 591f98e..a0bef49 100644 --- a/otus-02/src/otus_02/homework/palindrome.clj +++ b/otus-02/src/otus_02/homework/palindrome.clj @@ -1,6 +1,11 @@ (ns otus-02.homework.palindrome (:require [clojure.string :as string])) - -(defn is-palindrome [test-string]) - +(defn is-palindrome + "Func for check strings on palyndrome" + [s] + {:pre [(not= s nil)]} + (let [test-string (as-> s $ + (string/lower-case $) + (string/replace $ #"[^a-z]" ""))] + (= test-string (str/reverse test-string)))) diff --git a/otus-02/src/otus_02/homework/pangram.clj b/otus-02/src/otus_02/homework/pangram.clj index dc5d34c..5f989fc 100644 --- a/otus-02/src/otus_02/homework/pangram.clj +++ b/otus-02/src/otus_02/homework/pangram.clj @@ -1,6 +1,11 @@ (ns otus-02.homework.pangram (:require [clojure.string :as string])) - -(defn is-pangram [test-string]) - +(defn is-pangram [test-string] + "Func for check strings on pangram" + {:pre [(not= test-string nil)]} + (let [set-chars (-> test-string + string/lower-case + (string/replace #"[^a-z]" "") + set)] + (= (count set-chars) 26))) From ed4689c48d741a370d849361f6eee4c1e8390b5f Mon Sep 17 00:00:00 2001 From: kosbar Date: Mon, 22 Jul 2024 13:34:19 +0500 Subject: [PATCH 3/3] Homework for lesson Otus-02 --- otus-02/src/otus_02/homework/square_code.clj | 34 +++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/otus-02/src/otus_02/homework/square_code.clj b/otus-02/src/otus_02/homework/square_code.clj index 823a185..d4b5c41 100644 --- a/otus-02/src/otus_02/homework/square_code.clj +++ b/otus-02/src/otus_02/homework/square_code.clj @@ -1,4 +1,6 @@ -(ns otus-02.homework.square-code) +(ns otus-02.homework.square-code + (:require [clojure.string :as string]) + (:require [clojure.math :as math])) ;; Реализовать классический метод составления секретных сообщений, называемый `square code`. ;; Выведите закодированную версию полученного текста. @@ -48,9 +50,31 @@ "aohghn " "sseoau " +(defn add-spaces [amount line] + (apply str (concat line (repeat amount " ")))) +(defn encode-string [input] + ;; убираем знаки препинания, пробелы и переводим в нижний регистр + ;; а после переводим строку в вектор (line) + (let [inner (-> input + (string/lower-case) + (string/replace #"[^a-z]" "")) + size (count inner) + rows (int (math/sqrt (count inner))) + columns (inc rows) + line (->> inner + ;; добавляем пробелы к концу строки + (add-spaces (- (* columns rows) size)) + (vec))] -(defn encode-string [input]) - - -(defn decode-string [input]) + (string/join " " (map #(apply str %) + (partition rows + (replace line + (vec (loop [start 0 + rows 0 + l () + max (count line) + step columns] + (if (> rows (dec step)) + l + (recur (inc start) (inc rows) (concat l (range start max step)) max step))))))))))