Skip to content
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

HW 02 Shamshurin Ivan #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hotshotguy
Copy link

No description provided.

added recur palindrome function
@hotshotguy hotshotguy force-pushed the hw02 branch 2 times, most recently from 1d5a154 to 0564097 Compare December 25, 2024 14:23
Copy link

@Ivana- Ivana- left a comment

Choose a reason for hiding this comment

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

Хорошо, отметил некоторые моменты в коде

(let [go-next (= (get test-vec 0) (get test-vec (dec (count test-vec))))]
(cond
(empty? test-vec) true
(== (count test-vec) 1) true
Copy link

Choose a reason for hiding this comment

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

Модно, впервые вижу сравнение лонгов по ==

(empty? test-vec) true
(== (count test-vec) 1) true
(not go-next) false
:else (recur (subvec test-vec 1 (dec (count test-vec)))))))
Copy link

Choose a reason for hiding this comment

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

Если была здравая идея оптимизировать проверку, не создавая дубль перевернутой строки в памяти, то она полностью обесценилась созданием вектора и еще сабвекторов на каждой итерации...

(defn transform-string [s]
(-> s
(string/replace #"[,.-:;!?\"' ]" "")
(string/lower-case)))
Copy link

Choose a reason for hiding this comment

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

Одиночные функции-макросы можно без скобочек

(defn is-palindrome [test-string]
(let [s (transform-string test-string)
s-vec (vec s)]
(recur-palindrom s-vec)))
Copy link

Choose a reason for hiding this comment

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

Просто стиль - вы же выше умели в тред-макрос -> , зачем эти лишние леты и переменные?

(defn is-palindrome [s] (-> s transform-string vec recur-palindrom))

или если выпендриться, тогда уж

(def is-palindrome (comp recur-palindrom vec transform-string))


(defn is-palindrome [test-string])
(defn recur-palindrom [test-vec]
(let [go-next (= (get test-vec 0) (get test-vec (dec (count test-vec))))]
Copy link

Choose a reason for hiding this comment

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

let [last-index (dec (count test-vec))

и не придется дублировать и писать лишние скобки, да еще и без тред-макросов )


(comment
(is-pangram "The quick brown fox jumps over the lazy dog")
Copy link

Choose a reason for hiding this comment

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

Идея хорошая. Только у меня выдает тру на вызове

(is-pangram "abcdefgh!№%^*()&^$+_<>,./{}@#$~|")

(ns otus-02.homework.square-code
(:require [clojure.string :as string])
(:require [clojure.math :as math])
(:require [otus-02.homework.palindrome :as pal]))
Copy link

Choose a reason for hiding this comment

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

Одного реквайра с вектором векторов достаточно

(defn split-for-encode [col initial s]
(cond
(empty? s) initial
(<= (count s) col) (conj initial (trainling-spaces s col))
Copy link

Choose a reason for hiding this comment

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

(trainling-spaces s col) == (str s (format (str "%" col "s") ""))


(defn transpose-string-v [v]
(->> (map vec v)
Copy link

Choose a reason for hiding this comment

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

Лишнее действие, строка и так имплементирует интерфейс последовательности

(count)
(math/sqrt)
(math/ceil)
(int)))
Copy link

Choose a reason for hiding this comment

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

Можно без скобок

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants