Leap year: Difference between revisions
Content added Content deleted
m (even more concise) |
m (simplify) |
||
Line 2,738: | Line 2,738: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
<syntaxhighlight lang="ocaml">let is_leap_year ~year = |
<syntaxhighlight lang="ocaml">let is_leap_year ~year = |
||
year mod (if year mod 100 = 0 then 400 else 4) = 0</syntaxhighlight> |
|||
then (year mod 400) = 0 |
|||
else (year mod 4) = 0</syntaxhighlight> |
|||
Using Unix Time functions: |
Using Unix Time functions: |
||
<syntaxhighlight lang="ocaml">let is_leap_year ~year = |
<syntaxhighlight lang="ocaml">let is_leap_year ~year = |
||
Line 3,069: | Line 3,067: | ||
or |
or |
||
<syntaxhighlight lang="python">def is_leap_year(year): |
<syntaxhighlight lang="python">def is_leap_year(year): |
||
if year % 100 |
return not year % (4 if year % 100 else 400)</syntaxhighlight> |
||
return year % 400 == 0 |
|||
return year % 4 == 0</syntaxhighlight> |
|||
Asking for forgiveness instead of permission: |
Asking for forgiveness instead of permission: |
||
<syntaxhighlight lang="python">import datetime |
<syntaxhighlight lang="python">import datetime |