A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
4
Task/Leap-year/0DESCRIPTION
Normal file
4
Task/Leap-year/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Determine whether a given year is a leap year in the Gregorian calendar.
|
||||
|
||||
'''See Also'''
|
||||
* [[wp:Leap year|Leap year (wiki)]]
|
||||
2
Task/Leap-year/1META.yaml
Normal file
2
Task/Leap-year/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Date and time
|
||||
19
Task/Leap-year/ALGOL-68/leap-year.alg
Normal file
19
Task/Leap-year/ALGOL-68/leap-year.alg
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
MODE YEAR = INT, MONTH = INT, DAY = INT;
|
||||
|
||||
PROC year days = (YEAR year)DAY: # Ignore 1752 CE for the moment #
|
||||
( month days(year, 2) = 28 | 365 | 366 );
|
||||
|
||||
PROC month days = (YEAR year, MONTH month) DAY:
|
||||
( month | 31,
|
||||
28 + ABS (year MOD 4 = 0 AND year MOD 100 /= 0 OR year MOD 400 = 0),
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||
|
||||
PROC is leap year = (YEAR year)BOOL: year days(year)=366;
|
||||
|
||||
test:(
|
||||
[]INT test cases = (1900, 1994, 1996, 1997, 2000);
|
||||
FOR i TO UPB test cases DO
|
||||
YEAR year = test cases[i];
|
||||
printf(($g(0)" is "b("","not ")"a leap year."l$, year, is leap year(year)))
|
||||
OD
|
||||
)
|
||||
7
Task/Leap-year/AWK/leap-year.awk
Normal file
7
Task/Leap-year/AWK/leap-year.awk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function leapyear( year )
|
||||
{
|
||||
if ( year % 100 == 0 )
|
||||
return ( year % 400 == 0 )
|
||||
else
|
||||
return ( year % 4 == 0 )
|
||||
}
|
||||
6
Task/Leap-year/ActionScript/leap-year.as
Normal file
6
Task/Leap-year/ActionScript/leap-year.as
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
public function isLeapYear(year:int):Boolean {
|
||||
if (year % 100 == 0) {
|
||||
return (year % 400 == 0);
|
||||
}
|
||||
return (year % 4 == 0);
|
||||
}
|
||||
21
Task/Leap-year/Ada/leap-year.ada
Normal file
21
Task/Leap-year/Ada/leap-year.ada
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-- Incomplete code, just a sniplet to do the task. Can be used in any package or method.
|
||||
-- Adjust the type of Year if you use a different one.
|
||||
function Is_Leap_Year (Year : Integer) return Boolean is
|
||||
begin
|
||||
if Year rem 100 = 0 then
|
||||
return Year rem 400 = 0;
|
||||
else
|
||||
return Year rem 4 = 0;
|
||||
end if;
|
||||
end Is_Leap_Year;
|
||||
|
||||
|
||||
-- Should be faster without conditional and only one remainder (the other two are really binary and)
|
||||
function Is_Leap_Year (Year : Integer) return Boolean is
|
||||
begin
|
||||
return (Year rem 4 = 0) and ((Year rem 100 /= 0) or (Year rem 16 = 0));
|
||||
end Is_Leap_Year;
|
||||
|
||||
|
||||
-- To improve speed a bit more, use with
|
||||
pragma Inline (Is_Leap_Year);
|
||||
8
Task/Leap-year/AppleScript/leap-year.applescript
Normal file
8
Task/Leap-year/AppleScript/leap-year.applescript
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
on leap_year(y)
|
||||
if (y mod 100 is equal to 0) then
|
||||
return (y mod 400 is equal to 0)
|
||||
end if
|
||||
return (y mod 4 is equal to 0)
|
||||
end leap_year
|
||||
|
||||
leap_year(1900)
|
||||
6
Task/Leap-year/AutoHotkey/leap-year.ahk
Normal file
6
Task/Leap-year/AutoHotkey/leap-year.ahk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
MsgBox % "The year 1600 was " . (IsLeapYear(1600) ? "" : "not ") . "a leap year"
|
||||
|
||||
IsLeapYear(Year)
|
||||
{
|
||||
Return, !Mod(Year, 100) && !Mod(Year, 400) && !Mod(Year, 4)
|
||||
}
|
||||
15
Task/Leap-year/AutoIt/leap-year.autoit
Normal file
15
Task/Leap-year/AutoIt/leap-year.autoit
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;AutoIt Version: 3.2.10.0
|
||||
$Yr=1600
|
||||
ConsoleWrite ($Yr &" is ")
|
||||
if isLeapYear($Yr) Then
|
||||
ConsoleWrite ("leap year")
|
||||
Else
|
||||
ConsoleWrite ("not leap year")
|
||||
EndIf
|
||||
|
||||
Func isLeapYear($year)
|
||||
If IsInt($year/100) Then
|
||||
Return IsInt($year/400)
|
||||
EndIf
|
||||
Return IsInt($year/4)
|
||||
EndFunc
|
||||
25
Task/Leap-year/BASIC/leap-year.bas
Normal file
25
Task/Leap-year/BASIC/leap-year.bas
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
DECLARE FUNCTION diy% (y AS INTEGER)
|
||||
DECLARE FUNCTION isLeapYear% (yr AS INTEGER)
|
||||
DECLARE FUNCTION year% (date AS STRING)
|
||||
|
||||
PRINT isLeapYear(year(DATE$))
|
||||
|
||||
FUNCTION diy% (y AS INTEGER)
|
||||
IF y MOD 4 THEN
|
||||
diy = 365
|
||||
ELSEIF y MOD 100 THEN
|
||||
diy = 366
|
||||
ELSEIF y MOD 400 THEN
|
||||
diy = 365
|
||||
ELSE
|
||||
diy = 366
|
||||
END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION isLeapYear% (yr AS INTEGER)
|
||||
isLeapYear = (366 = diy(yr))
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION year% (date AS STRING)
|
||||
year% = VAL(RIGHT$(date, 4))
|
||||
END FUNCTION
|
||||
12
Task/Leap-year/BBC-BASIC/leap-year.bbc
Normal file
12
Task/Leap-year/BBC-BASIC/leap-year.bbc
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
REPEAT
|
||||
INPUT "Enter a year: " year%
|
||||
IF FNleap(year%) THEN
|
||||
PRINT ;year% " is a leap year"
|
||||
ELSE
|
||||
PRINT ;year% " is not a leap year"
|
||||
ENDIF
|
||||
UNTIL FALSE
|
||||
END
|
||||
|
||||
DEF FNleap(yr%)
|
||||
= (yr% MOD 4 = 0) AND ((yr% MOD 400 = 0) OR (yr% MOD 100 <> 0))
|
||||
15
Task/Leap-year/Bracmat/leap-year.bracmat
Normal file
15
Task/Leap-year/Bracmat/leap-year.bracmat
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
( leap-year
|
||||
=
|
||||
. mod$(!arg.100):0
|
||||
& `(mod$(!arg.400):0) { The backtick skips the remainder of the OR operation,
|
||||
even if the tested condition fails. }
|
||||
| mod$(!arg.4):0
|
||||
)
|
||||
& 1600 1700 1899 1900 2000 2006 2012:?tests
|
||||
& whl
|
||||
' ( !tests:%?test ?tests
|
||||
& ( leap-year$!test&out$(!test " is a leap year")
|
||||
| out$(!test " is not a leap year")
|
||||
)
|
||||
)
|
||||
& ;
|
||||
16
Task/Leap-year/C/leap-year.c
Normal file
16
Task/Leap-year/C/leap-year.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool is_leap_year(int year)
|
||||
{
|
||||
return !(year % 4) && year % 100 || !(year % 400);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int test_case[] = {1900, 1994, 1996, 1997, 2000}, key, end;
|
||||
for (key = 0, end = sizeof(test_case)/sizeof(test_case[0]); key < end; ++key) {
|
||||
int year = test_case[key];
|
||||
printf("%d is %sa leap year.\n", year, is_leap_year(year) ? "" : "not ");
|
||||
}
|
||||
}
|
||||
2
Task/Leap-year/Clojure/leap-year.clj
Normal file
2
Task/Leap-year/Clojure/leap-year.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defn leap-year? [y]
|
||||
(and (zero? (mod y 4)) (or (pos? (mod y 100)) (zero? (mod y 400)))))
|
||||
4
Task/Leap-year/Common-Lisp/leap-year.lisp
Normal file
4
Task/Leap-year/Common-Lisp/leap-year.lisp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(defun leap-year-p (year)
|
||||
(destructuring-bind (fh h f)
|
||||
(mapcar #'(lambda (n) (zerop (mod year n))) '(400 100 4))
|
||||
(or fh (and (not h) f))))
|
||||
13
Task/Leap-year/D/leap-year.d
Normal file
13
Task/Leap-year/D/leap-year.d
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import std.algorithm;
|
||||
|
||||
bool leapYear(in uint y) pure nothrow {
|
||||
return (y % 4) == 0 && (y % 100 || (y % 400) == 0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto good = [1600, 1660, 1724, 1788, 1848, 1912, 1972, 2032,
|
||||
2092, 2156, 2220, 2280, 2344, 2348];
|
||||
auto bad = [1698, 1699, 1700, 1750, 1800, 1810, 1900, 1901,
|
||||
1973, 2100, 2107, 2200, 2203, 2289];
|
||||
assert(filter!leapYear(bad ~ good).equal(good));
|
||||
}
|
||||
21
Task/Leap-year/DWScript/leap-year.dwscript
Normal file
21
Task/Leap-year/DWScript/leap-year.dwscript
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
function IsLeapYear(y : Integer) : Boolean;
|
||||
begin
|
||||
Result:= (y mod 4 = 0)
|
||||
and ( ((y mod 100) <> 0)
|
||||
or ((y mod 400) = 0) );
|
||||
end;
|
||||
|
||||
const good : array [0..13] of Integer =
|
||||
[1600,1660,1724,1788,1848,1912,1972,2032,2092,2156,2220,2280,2344,2348];
|
||||
const bad : array [0..13] of Integer =
|
||||
[1698,1699,1700,1750,1800,1810,1900,1901,1973,2100,2107,2200,2203,2289];
|
||||
|
||||
var i : Integer;
|
||||
|
||||
PrintLn('Checking leap years');
|
||||
for i in good do
|
||||
if not IsLeapYear(i) then PrintLn(i);
|
||||
|
||||
PrintLn('Checking non-leap years');
|
||||
for i in bad do
|
||||
if IsLeapYear(i) then PrintLn(i);
|
||||
19
Task/Leap-year/Delphi/leap-year.delphi
Normal file
19
Task/Leap-year/Delphi/leap-year.delphi
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
program TestLeapYear;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
var
|
||||
Year: Integer;
|
||||
|
||||
begin
|
||||
Write('Enter the year: ');
|
||||
Readln(Year);
|
||||
if IsLeapYear(Year) then
|
||||
Writeln(Year, ' is a Leap year')
|
||||
else
|
||||
Writeln(Year, ' is not a Leap year');
|
||||
Readln;
|
||||
end.
|
||||
2
Task/Leap-year/Ela/leap-year.ela
Normal file
2
Task/Leap-year/Ela/leap-year.ela
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
isLeap y | y % 100 == 0 = y % 400 == 0
|
||||
| else = y % 4 == 0
|
||||
7
Task/Leap-year/Erlang/leap-year.erl
Normal file
7
Task/Leap-year/Erlang/leap-year.erl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-module(gregorian).
|
||||
-export([leap/1]).
|
||||
|
||||
leap(Year) when Year rem 4 /= 0 -> false;
|
||||
leap(Year) when Year rem 100 /= 0 -> true;
|
||||
leap(Year) when Year rem 400 == 0 -> true;
|
||||
leap(_) -> false.
|
||||
3
Task/Leap-year/Euphoria/leap-year.euphoria
Normal file
3
Task/Leap-year/Euphoria/leap-year.euphoria
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function isLeapYear(integer year)
|
||||
return remainder(year,4)=0 and remainder(year,100)!=0 or remainder(year,400)=0
|
||||
end function
|
||||
2
Task/Leap-year/Factor/leap-year.factor
Normal file
2
Task/Leap-year/Factor/leap-year.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USING: calendar prettyprint ;
|
||||
2011 leap-year? .
|
||||
4
Task/Leap-year/Forth/leap-year.fth
Normal file
4
Task/Leap-year/Forth/leap-year.fth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
: leap-year? ( y -- ? )
|
||||
dup 400 mod 0= if drop true exit then
|
||||
dup 100 mod 0= if drop false exit then
|
||||
4 mod 0= ;
|
||||
17
Task/Leap-year/Fortran/leap-year.f
Normal file
17
Task/Leap-year/Fortran/leap-year.f
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program leap
|
||||
implicit none
|
||||
|
||||
write(*,*) leap_year([1900, 1996, 1997, 2000])
|
||||
|
||||
contains
|
||||
|
||||
pure elemental function leap_year(y) result(is_leap)
|
||||
implicit none
|
||||
logical :: is_leap
|
||||
integer,intent(in) :: y
|
||||
|
||||
is_leap = (mod(y,4)==0 .and. .not. mod(y,100)==0) .or. (mod(y,400)==0)
|
||||
|
||||
end function leap_year
|
||||
|
||||
end program leap
|
||||
8
Task/Leap-year/GAP/leap-year.gap
Normal file
8
Task/Leap-year/GAP/leap-year.gap
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
IsLeapYear := function(n)
|
||||
return (n mod 4 = 0) and ((n mod 100 <> 0) or (n mod 400 = 0));
|
||||
end;
|
||||
|
||||
# alternative using built-in function
|
||||
IsLeapYear := function(n)
|
||||
return DaysInYear(n) = 366;
|
||||
end;
|
||||
3
Task/Leap-year/Go/leap-year.go
Normal file
3
Task/Leap-year/Go/leap-year.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
func isLeap(year int) bool {
|
||||
return year%400 == 0 || year%4 == 0 && year%100 != 0
|
||||
}
|
||||
1
Task/Leap-year/Groovy/leap-year.groovy
Normal file
1
Task/Leap-year/Groovy/leap-year.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
(1900..2012).findAll {new GregorianCalendar().isLeapYear(it)}.each {println it}
|
||||
9
Task/Leap-year/Haskell/leap-year-1.hs
Normal file
9
Task/Leap-year/Haskell/leap-year-1.hs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import Data.List
|
||||
import Control.Monad
|
||||
import Control.Arrow
|
||||
|
||||
leaptext x b | b = show x ++ " is a leap year"
|
||||
| otherwise = show x ++ " is not a leap year"
|
||||
|
||||
isleapsf j | 0==j`mod`100 = 0 == j`mod`400
|
||||
| otherwise = 0 == j`mod`4
|
||||
1
Task/Leap-year/Haskell/leap-year-2.hs
Normal file
1
Task/Leap-year/Haskell/leap-year-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
isleap = foldl1 ((&&).not).flip map [400, 100, 4]. ((0==).).mod
|
||||
6
Task/Leap-year/Haskell/leap-year-3.hs
Normal file
6
Task/Leap-year/Haskell/leap-year-3.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
*Main> mapM_ (putStrLn. (ap leaptext isleap)) [1900,1994,1996,1997,2000]
|
||||
1900 is not a leap year
|
||||
1994 is not a leap year
|
||||
1996 is a leap year
|
||||
1997 is not a leap year
|
||||
2000 is a leap year
|
||||
8
Task/Leap-year/Icon/leap-year.icon
Normal file
8
Task/Leap-year/Icon/leap-year.icon
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
procedure main(arglist)
|
||||
every y := !([2000,1900,2012]|||arglist) do
|
||||
write("The year ",y," is ", leapyear(y) | "not ","a leap year.")
|
||||
end
|
||||
|
||||
procedure leapyear(year) #: determine if year is leap
|
||||
if (numeric(year) % 4 = 0 & year % 100 ~= 0) | (numeric(year) % 400 = 0) then return
|
||||
end
|
||||
1
Task/Leap-year/J/leap-year-1.j
Normal file
1
Task/Leap-year/J/leap-year-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
isLeap=: 0 -/@:= 4 100 400 |/ ]
|
||||
2
Task/Leap-year/J/leap-year-2.j
Normal file
2
Task/Leap-year/J/leap-year-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
isLeap 1900 1996 1997 2000
|
||||
0 1 0 1
|
||||
1
Task/Leap-year/Java/leap-year-1.java
Normal file
1
Task/Leap-year/Java/leap-year-1.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
new java.util.GregorianCalendar().isLeapYear(year)
|
||||
5
Task/Leap-year/Java/leap-year-2.java
Normal file
5
Task/Leap-year/Java/leap-year-2.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
public static boolean isLeapYear(int year){
|
||||
if(year % 100 == 0)
|
||||
return year % 400 == 0;
|
||||
return year % 4 == 0;
|
||||
}
|
||||
1
Task/Leap-year/JavaScript/leap-year-1.js
Normal file
1
Task/Leap-year/JavaScript/leap-year-1.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
var isLeapYear = function (year) { return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0); };
|
||||
2
Task/Leap-year/JavaScript/leap-year-2.js
Normal file
2
Task/Leap-year/JavaScript/leap-year-2.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// Month values start at 0, so 1 is for February
|
||||
var isLeapYear = function (year) { return new Date(year, 1, 29).getDate() === 29; };
|
||||
4
Task/Leap-year/K/leap-year.k
Normal file
4
Task/Leap-year/K/leap-year.k
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
leapyear:{(+/~x!'4 100 400)!2}
|
||||
|
||||
a@&leapyear'a:1900,1994,1996,1997,2000
|
||||
1996 2000
|
||||
10
Task/Leap-year/Liberty-BASIC/leap-year-1.liberty
Normal file
10
Task/Leap-year/Liberty-BASIC/leap-year-1.liberty
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
if leap(1996)then
|
||||
print "leap"
|
||||
else
|
||||
print "ordinary"
|
||||
end if
|
||||
wait
|
||||
|
||||
function leap(n)
|
||||
leap=date$("2/29/";n)
|
||||
end function
|
||||
14
Task/Leap-year/Liberty-BASIC/leap-year-2.liberty
Normal file
14
Task/Leap-year/Liberty-BASIC/leap-year-2.liberty
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
year = 1908
|
||||
select case
|
||||
case year mod 400 = 0
|
||||
leapYear = 1
|
||||
case year mod 4 = 0 and year mod 100 <> 0
|
||||
leapYear = 1
|
||||
case else
|
||||
leapYear = 0
|
||||
end select
|
||||
if leapYear = 1 then
|
||||
print year;" is a leap year."
|
||||
else
|
||||
print year;" is not a leap year."
|
||||
end if
|
||||
6
Task/Leap-year/Logo/leap-year.logo
Normal file
6
Task/Leap-year/Logo/leap-year.logo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
to multiple? :n :d
|
||||
output equal? 0 modulo :n :d
|
||||
end
|
||||
to leapyear? :y
|
||||
output ifelse multiple? :y 100 [multiple? :y 400] [multiple? :y 4]
|
||||
end
|
||||
5
Task/Leap-year/Logtalk/leap-year.logtalk
Normal file
5
Task/Leap-year/Logtalk/leap-year.logtalk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
leap_year(Year) :-
|
||||
( mod(Year, 4) =:= 0, mod(Year, 100) =\= 0 ->
|
||||
true
|
||||
; mod(Year, 400) =:= 0
|
||||
).
|
||||
3
Task/Leap-year/Lua/leap-year.lua
Normal file
3
Task/Leap-year/Lua/leap-year.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function isLeapYear(year)
|
||||
return year%4==0 and (year%100~=0 or year%400==0)
|
||||
end
|
||||
3
Task/Leap-year/MATLAB/leap-year.m
Normal file
3
Task/Leap-year/MATLAB/leap-year.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function TrueFalse = isLeapYear(year)
|
||||
TrueFalse = (eomday(year,2) == 29);
|
||||
end
|
||||
2
Task/Leap-year/MUMPS/leap-year.mumps
Normal file
2
Task/Leap-year/MUMPS/leap-year.mumps
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ILY(X) ;IS IT A LEAP YEAR?
|
||||
QUIT ((X#4=0)&(X#100'=0))!((X#100=0)&(X#400=0))
|
||||
1
Task/Leap-year/Mathematica/leap-year.mathematica
Normal file
1
Task/Leap-year/Mathematica/leap-year.mathematica
Normal file
|
|
@ -0,0 +1 @@
|
|||
isLeapYear[y_]:= y~Mod~4 == 0 && (y~Mod~100 != 0 || y~Mod~400 == 0)
|
||||
2
Task/Leap-year/Maxima/leap-year.maxima
Normal file
2
Task/Leap-year/Maxima/leap-year.maxima
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
leapyearp(year) := is(mod(year, 4) = 0 and
|
||||
(mod(year, 100) # 0 or mod(year, 400) = 0))$
|
||||
7
Task/Leap-year/PHP/leap-year-1.php
Normal file
7
Task/Leap-year/PHP/leap-year-1.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
function isLeapYear(year) {
|
||||
if (year % 100 == 0) {
|
||||
return (year % 400 == 0);
|
||||
}
|
||||
return (year % 4 == 0);
|
||||
}
|
||||
4
Task/Leap-year/PHP/leap-year-2.php
Normal file
4
Task/Leap-year/PHP/leap-year-2.php
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
function isLeapYear(year) {
|
||||
return (date('L', mktime(0, 0, 0, 2, 1, year)) === '1')
|
||||
}
|
||||
7
Task/Leap-year/Perl/leap-year-1.pl
Normal file
7
Task/Leap-year/Perl/leap-year-1.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
sub leap {
|
||||
my $yr = $_[0];
|
||||
if ($yr % 100 == 0) {
|
||||
return ($yr % 400 == 0);
|
||||
}
|
||||
return ($yr % 4 == 0);
|
||||
}
|
||||
1
Task/Leap-year/Perl/leap-year-2.pl
Normal file
1
Task/Leap-year/Perl/leap-year-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
sub leap {!($_[0] % 100) ? !($_[0] % 400) : !($_[0] % 4)}
|
||||
6
Task/Leap-year/Perl/leap-year-3.pl
Normal file
6
Task/Leap-year/Perl/leap-year-3.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use Date::Manip;
|
||||
Date_LeapYear($year);
|
||||
|
||||
use Date::Manip::Base;
|
||||
my $dmb = new Date::Manip::Base;
|
||||
$dmb->leapyear($year);
|
||||
2
Task/Leap-year/PicoLisp/leap-year.l
Normal file
2
Task/Leap-year/PicoLisp/leap-year.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(de isLeapYear (Y)
|
||||
(bool (date Y 2 29)) )
|
||||
10
Task/Leap-year/Prolog/leap-year-1.pro
Normal file
10
Task/Leap-year/Prolog/leap-year-1.pro
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
leap_year(L) :-
|
||||
partition(is_leap_year, L, LIn, LOut),
|
||||
format('leap years : ~w~n', [LIn]),
|
||||
format('not leap years : ~w~n', [LOut]).
|
||||
|
||||
is_leap_year(Year) :-
|
||||
R4 is Year mod 4,
|
||||
R100 is Year mod 100,
|
||||
R400 is Year mod 400,
|
||||
( (R4 = 0, R100 \= 0); R400 = 0).
|
||||
4
Task/Leap-year/Prolog/leap-year-2.pro
Normal file
4
Task/Leap-year/Prolog/leap-year-2.pro
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
?- leap_year([1900,1994,1996,1997,2000 ]).
|
||||
leap years : [1996,2000]
|
||||
not leap years : [1900,1994,1997]
|
||||
L = [1900,1994,1996,1997,2000].
|
||||
2
Task/Leap-year/Python/leap-year-1.py
Normal file
2
Task/Leap-year/Python/leap-year-1.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import calendar
|
||||
calendar.isleap(year)
|
||||
4
Task/Leap-year/Python/leap-year-2.py
Normal file
4
Task/Leap-year/Python/leap-year-2.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def is_leap_year(year):
|
||||
if year % 100 == 0:
|
||||
return year % 400 == 0
|
||||
return year % 4 == 0
|
||||
8
Task/Leap-year/Python/leap-year-3.py
Normal file
8
Task/Leap-year/Python/leap-year-3.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import datetime
|
||||
|
||||
def is_leap_year(year):
|
||||
try:
|
||||
datetime.date(year, 2, 29)
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
7
Task/Leap-year/R/leap-year.r
Normal file
7
Task/Leap-year/R/leap-year.r
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
isLeapYear <- function(year) {
|
||||
ifelse(year%%100==0, year%%400==0, year%%4==0)
|
||||
}
|
||||
|
||||
for (y in c(1900, 1994, 1996, 1997, 2000)) {
|
||||
print(paste(y, " is ", ifelse(isLeapYear(y), "", "not "), "a leap year.", sep=""))
|
||||
}
|
||||
3
Task/Leap-year/REXX/leap-year-1.rexx
Normal file
3
Task/Leap-year/REXX/leap-year-1.rexx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
leapyear: procedure; parse arg yr
|
||||
|
||||
return yr//400==0 | (yr//100\==0 & yr//4==0)
|
||||
1
Task/Leap-year/REXX/leap-year-2.rexx
Normal file
1
Task/Leap-year/REXX/leap-year-2.rexx
Normal file
|
|
@ -0,0 +1 @@
|
|||
leapyear: return arg(1)//400==0 | (arg(1)//100\==0 & arg(1)//4==0)
|
||||
2
Task/Leap-year/Racket/leap-year.rkt
Normal file
2
Task/Leap-year/Racket/leap-year.rkt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(define (leap-year? y)
|
||||
(and (zero? (modulo y 4)) (or (positive? (modulo y 100)) (zero? (modulo y 400)))))
|
||||
4
Task/Leap-year/Ruby/leap-year-1.rb
Normal file
4
Task/Leap-year/Ruby/leap-year-1.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
require 'date'
|
||||
def leap_year?(year)
|
||||
Date.new(year).leap?
|
||||
end
|
||||
3
Task/Leap-year/Ruby/leap-year-2.rb
Normal file
3
Task/Leap-year/Ruby/leap-year-2.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[2000, 1900, 1800, 1700, 1600, 1500, 1400].each do |year|
|
||||
print year, (leap_year? year) ? " is" : " is not", " a leap year.\n"
|
||||
end
|
||||
4
Task/Leap-year/Ruby/leap-year-3.rb
Normal file
4
Task/Leap-year/Ruby/leap-year-3.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
require 'date'
|
||||
def leap_year?(year)
|
||||
Date.new(year, 1, 1, Date::GREGORIAN).leap?
|
||||
end
|
||||
2
Task/Leap-year/Scala/leap-year-1.scala
Normal file
2
Task/Leap-year/Scala/leap-year-1.scala
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
//use Java's calendar class
|
||||
new java.util.GregorianCalendar().isLeapYear(year)
|
||||
8
Task/Leap-year/Scala/leap-year-2.scala
Normal file
8
Task/Leap-year/Scala/leap-year-2.scala
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
def isLeapYear(year:Int)=if (year%100==0) year%400==0 else year%4==0;
|
||||
|
||||
//or use Java's calendar class
|
||||
def isLeapYear(year:Int):Boolean = {
|
||||
val c = new java.util.GregorianCalendar
|
||||
c.setGregorianChange(new java.util.Date(Long.MinValue))
|
||||
c.isLeapYear(year)
|
||||
}
|
||||
4
Task/Leap-year/Scheme/leap-year.ss
Normal file
4
Task/Leap-year/Scheme/leap-year.ss
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(define (leap-year? n)
|
||||
(apply (lambda (a b c) (or a (and (not b) c)))
|
||||
(map (lambda (m) (zero? (remainder n m)))
|
||||
'(400 100 4))))
|
||||
7
Task/Leap-year/Tcl/leap-year-1.tcl
Normal file
7
Task/Leap-year/Tcl/leap-year-1.tcl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
proc isleap1 {year} {
|
||||
return [expr {($year % 4 == 0) && (($year % 100 != 0) || ($year % 400 == 0))}]
|
||||
}
|
||||
isleap1 1988 ;# => 1
|
||||
isleap1 1989 ;# => 0
|
||||
isleap1 1900 ;# => 0
|
||||
isleap1 2000 ;# => 1
|
||||
7
Task/Leap-year/Tcl/leap-year-2.tcl
Normal file
7
Task/Leap-year/Tcl/leap-year-2.tcl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
proc isleap2 year {
|
||||
return [expr {[clock format [clock scan "$year-02-29" -format "%Y-%m-%d"] -format "%m-%d"] eq "02-29"}]
|
||||
}
|
||||
isleap2 1988 ;# => 1
|
||||
isleap2 1989 ;# => 0
|
||||
isleap2 1900 ;# => 0
|
||||
isleap2 2000 ;# => 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue