March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,8 @@
leapyear(year)
{
if (Mod(year, 100) = 0)
return (Mod(year, 400) = 0)
return (Mod(year, 4) = 0)
}
MsgBox, % leapyear(1604)

View file

@ -0,0 +1,6 @@
IsLeapYear(Year)
{
return !Mod(Year, 4) && Mod(Year, 100) || !Mod(Year, 400)
}
MsgBox % "The year 1604 was " (IsLeapYear(1604) ? "" : "not ") "a leap year"

View file

@ -1,6 +0,0 @@
MsgBox % "The year 1600 was " . (IsLeapYear(1600) ? "" : "not ") . "a leap year"
IsLeapYear(Year)
{
Return, !Mod(Year, 100) && !Mod(Year, 400) && !Mod(Year, 4)
}

View file

@ -0,0 +1,5 @@
leap(y) = y%4==0 && (y<1582 || y%400==0 || y%100!=0)
# some tests
@assert all([leap(yr) for yr in [2400, 2012, 2000, 1600, 1500, 1400]])
@assert all([~leap(yr) for yr in [2100, 2014, 1900, 1800, 1700, 1499]])

View file

@ -0,0 +1,4 @@
:- pred is_leap_year(int::in) is semidet.
is_leap_year(Year) :-
( if Year mod 100 = 0 then Year mod 400 = 0 else Year mod 4 = 0 ).

View file

@ -0,0 +1,18 @@
:- module leap_year.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, list, string.
main(!IO) :-
Years = [1600, 1700, 1899, 1900, 2000, 2006, 2012],
io.write_list(Years, "", write_year_kind, !IO).
:- pred write_year_kind(int::in, io::di, io::uo) is det.
write_year_kind(Year, !IO) :-
io.format("%d %s a leap year.\n",
[i(Year), s(if is_leap_year(Year) then "is" else "is not" )], !IO).

View file

@ -1,7 +1,7 @@
sub leap {
my $yr = $_[0];
if ($yr % 100 == 0) {
return ($yr % 400 == 0);
sub isleap {
my $year = shift;
if ($year % 100 == 0) {
return ($year % 400 == 0);
}
return ($yr % 4 == 0);
return ($year % 4 == 0);
}

View file

@ -1 +1 @@
sub leap {!($_[0] % 100) ? !($_[0] % 400) : !($_[0] % 4)}
sub isleap { !($_[0] % 100) ? !($_[0] % 400) : !($_[0] % 4) }

View file

@ -1,6 +1,10 @@
use Date::Manip;
Date_LeapYear($year);
print Date_LeapYear(2000);
use Date::Manip::Base;
my $dmb = new Date::Manip::Base;
$dmb->leapyear($year);
print $dmb->leapyear(2000);
use DateTime;
my $date = DateTime->new(year => 2000);
print $date->is_leap_year();