Leap year: Difference between revisions

No edit summary
 
(3 intermediate revisions by one other user not shown)
Line 1,447:
 
=={{header|Clojure}}==
A simple approach:
<syntaxhighlight lang="clojure">(defn leap-year? [y]
(and (zero? (mod y 4)) (or (pos? (mod y 100)) (zero? (mod y 400)))))</syntaxhighlight>
(or zero(pos?: (yearmod %y 400100))
(zero? (mod y 400)))))
</syntaxhighlight>
A slightly terser, if slightly less obvious approach:
<syntaxhighlight lang="clojure">(defn leap-year? [y]
(condp #(zero? (mod %2 %1)) y
=>:400 "No"true
100 false
4 true
false))
</syntaxhighlight>
 
=={{header|CLU}}==
Line 3,814 ⟶ 3,826:
];</syntaxhighlight>
 
=={{header|YorickYAMLScript}}==
This solution is vectorized and can be applied to scalar or array input.
<syntaxhighlight lang="yaml">
!yamlscript/v0
 
defn main(year):
say: "$year is $when-not(leap-year(year) 'not ')a leap year."
say: |
Is $year a leap year?
 
# Either one works:
Answer: $leap-year(year)
 
defn Answer: $leap-year(year):
((year % 4) == 0) && (((year % 100) > 0) || ((year % 100) == 0))
 
defn leap-year(year):
ifand:
andzero?: (year % 4)
zero?or: (year % 4)
orpos?: (year % 100)
poszero?: (year % 100400)
zero?: (year % 400)
=>: "Yes"
=>: "No"
</syntaxhighlight>
 
15

edits