Data update

This commit is contained in:
Ingy döt Net 2024-03-06 22:25:12 -08:00
parent ed705008a8
commit 0df55f9f24
2196 changed files with 32999 additions and 3075 deletions

View file

@ -0,0 +1,2 @@
pub fun is-leap-year(year: int)
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)

View file

@ -0,0 +1,2 @@
pub fun is-leap-year'(year: int)
year % (if year % 100 == 0 then 400 else 4) == 0

View file

@ -0,0 +1,6 @@
import std/time
import std/time/date
import std/time/time
pub fun is-leap-year''(year: int)
Date(year, 2, 28).time.add-days(1).day == 29

View file

@ -1,5 +1 @@
is_leap() {
local year=$(( 10#${1:?'Missing year'} ))
(( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )) && return 0
return 1
}
is_leap() (( year=${1-0}, year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 )))

View file

@ -0,0 +1,16 @@
!yamlscript/v0
defn main(year):
say: "$year is $when-not(leap-year(year) 'not ')a leap year."
# Either one works:
defn leap-year(year):
((year % 4) == 0) && (((year % 100) > 0) || ((year % 100) == 0))
defn leap-year(year):
and:
zero?: (year % 4)
or:
pos?: (year % 100)
zero?: (year % 400)

View file

@ -0,0 +1,35 @@
/// The type that holds the current year, i.e. 2016
pub const Year = u16;
/// Returns true for years with 366 days
/// and false for years with 365 days.
pub fn isLeapYear(year: Year) bool {
// In the western Gregorian Calendar leap a year is
// a multiple of 4, excluding multiples of 100, and
// adding multiples of 400. In code:
//
// if (@mod(year, 4) != 0)
// return false;
// if (@mod(year, 100) != 0)
// return true;
// return (0 == @mod(year, 400));
// The following is equivalent to the above
// but uses bitwise operations when testing
// for divisibility, masking with 3 as test
// for multiples of 4 and with 15 as a test
// for multiples of 16. Multiples of 16 and
// 100 are, conveniently, multiples of 400.
const mask: Year = switch (year % 100) {
0 => 0b1111,
else => 0b11,
};
return 0 == year & mask;
}
test "isLeapYear" {
try testing.expectEqual(false, isLeapYear(2095));
try testing.expectEqual(true, isLeapYear(2096));
try testing.expectEqual(false, isLeapYear(2100));
try testing.expectEqual(true, isLeapYear(2400));
}