-
Notifications
You must be signed in to change notification settings - Fork 8
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
HW04 - домашнее задание. #12
base: main
Are you sure you want to change the base?
Changes from all commits
8413318
420ade7
23e0285
c83e36d
05f42da
e179205
fb74e00
b03f822
33450fc
7a2f434
060d535
84fca7b
69c8e2c
bf4bc55
5ccd4c0
c25915b
9c3fca9
a5e1d54
85d895d
e982f81
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(ns otus.homework) | ||
|
||
|
||
(defn solution "Add your solution as fuction body here" []) | ||
|
||
(defn solution "Add your solution as fuction body here" [] | ||
(double (/ (+ 5 (+ 4 (- 2 (- 3 (+ 6 (/ 4 5)))))) | ||
(* 3 (* (- 2 7) (- 6 2)))))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
(ns otus-02.homework.palindrome | ||
(:require [clojure.string :as string])) | ||
|
||
|
||
(defn is-palindrome [test-string]) | ||
(defn is-palindrome [test-string] | ||
(let [normal-str (string/upper-case (string/replace test-string #"[^a-zA-Z0-9]" "")) | ||
invert-str (string/reverse normal-str)] (= normal-str invert-str))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
(ns otus-02.homework.pangram | ||
(:require [clojure.string :as string])) | ||
|
||
;;(defn is-pangram [test-string] | ||
;; (let [alphabet "abcdefghijklmnopqrstuvwxyz" | ||
;; alph-vec (map str (vec alphabet)) | ||
;; normal-string1 (string/lower-case test-string) | ||
;; normal-string (map str | ||
;; (filter #(> (.indexOf alphabet (str %1)) -1) | ||
;; normal-string1)) | ||
;; chr-in-alpha-list (map #(.indexOf normal-string %) alph-vec)] | ||
;; (= (count (filter #(= % -1) chr-in-alpha-list)) 0))) | ||
|
||
(defn is-pangram [test-string]) | ||
|
||
(defn is-pangram [test-string] | ||
(let [alphabet "abcdefghijklmnopqrstuvwxyz" | ||
normal-string (-> test-string | ||
(string/replace #"[\s\W]" "") | ||
string/lower-case)] | ||
(= (set alphabet) (set normal-string)))) | ||
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. Раз уж с множествами работаете, то можно было бы проверить, что пересечение |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ | |
"Функция возвращает true, если из букв в строке letters | ||
можно составить слово word." | ||
[letters word] | ||
nil) | ||
(let [letters-set (set (mapv str letters)) | ||
word-set (set (mapv str word))] | ||
(= (clojure.set/intersection letters-set word-set) word-set))) | ||
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. А вот здесь использование множеств не сработает. Потому что, приводя строку к множеству, вы теряете информацию о количестве повторов букв. А чтобы составить word из letters может потребовать более одного экземпляра той или иной буквы. Вы точно запускали тесты? Среди тестовых примеров точно есть такой, в которому буквы в собираемом слове повторяются. |
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.
"тело" в let лучше переносить на новую строчку.