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
3 changes: 2 additions & 1 deletion otus-01/src/otus/homework.clj
Original file line number Diff line number Diff line change
@@ -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))))

2 changes: 1 addition & 1 deletion otus-01/test/otus/homework_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
11 changes: 8 additions & 3 deletions otus-02/src/otus_02/homework/palindrome.clj
Original file line number Diff line number Diff line change
@@ -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))))
11 changes: 8 additions & 3 deletions otus-02/src/otus_02/homework/pangram.clj
Original file line number Diff line number Diff line change
@@ -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)))
34 changes: 29 additions & 5 deletions otus-02/src/otus_02/homework/square_code.clj
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 [clojure.string :as string])
(:require [clojure.math :as math]))

;; Реализовать классический метод составления секретных сообщений, называемый `square code`.
;; Выведите закодированную версию полученного текста.
Expand Down Expand Up @@ -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))))))))))