Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
2
Task/Leap-year/Koka/leap-year-1.koka
Normal file
2
Task/Leap-year/Koka/leap-year-1.koka
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub fun is-leap-year(year: int)
|
||||
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
|
||||
2
Task/Leap-year/Koka/leap-year-2.koka
Normal file
2
Task/Leap-year/Koka/leap-year-2.koka
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub fun is-leap-year'(year: int)
|
||||
year % (if year % 100 == 0 then 400 else 4) == 0
|
||||
6
Task/Leap-year/Koka/leap-year-3.koka
Normal file
6
Task/Leap-year/Koka/leap-year-3.koka
Normal 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
|
||||
|
|
@ -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 )))
|
||||
|
|
|
|||
16
Task/Leap-year/YAMLScript/leap-year.ys
Normal file
16
Task/Leap-year/YAMLScript/leap-year.ys
Normal 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)
|
||||
35
Task/Leap-year/Zig/leap-year-2.zig
Normal file
35
Task/Leap-year/Zig/leap-year-2.zig
Normal 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));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue