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
Add leap year task #402
Add leap year task #402
Conversation
Issue #403 |
:arguments [2020]}]) | ||
|
||
(defn solution [year] | ||
(if (and (zero? (mod year 4)) (not (and (zero? (mod year 100)) (not= (mod year 400) 0)))) true false)) |
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.
предлагаю убрать if, так как внутри итак булево выражение и не нужно его явно отображать. А для явности выражения использовать let чтобы дать поясняющие имена составляющим выражение частям.
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.
Я что-то слишком сильно зациклился на решении первоисточника)
Такой вариант лучше будет?
(defn solution [year] (cond (zero? (mod year 400)) true (zero? (mod year 100)) false (zero? (mod year 4)) true :default false))
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.
А,черт.форматирование сломалось, сейчас комитну тогда
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.
(zero? (mod year 400))
уже булево выражение, его можно ни в if ни в cond не писать.
предлагаю что-то вроде такого
(defn solution [year]
(letfn [(divisible? [a b]
(zero? (mod a b)))]
(and (divisible? year 4) (not (divisible? year 400)))))
No description provided.