Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Leap-year/00-META.yaml
Normal file
3
Task/Leap-year/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Leap_year
|
||||
note: Date and time
|
||||
8
Task/Leap-year/00-TASK.txt
Normal file
8
Task/Leap-year/00-TASK.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
;Task:
|
||||
Determine whether a given year is a leap year in the Gregorian calendar.
|
||||
|
||||
|
||||
;See also:
|
||||
* [[wp:Leap year|Leap year (wiki)]]
|
||||
<br><br>
|
||||
|
||||
4
Task/Leap-year/11l/leap-year.11l
Normal file
4
Task/Leap-year/11l/leap-year.11l
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
F is_leap_year(year)
|
||||
I year % 100 == 0
|
||||
R year % 400 == 0
|
||||
R year % 4 == 0
|
||||
18
Task/Leap-year/360-Assembly/leap-year.360
Normal file
18
Task/Leap-year/360-Assembly/leap-year.360
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
LPCK CSECT
|
||||
USING LPCK,15
|
||||
STM 0,12,20(13) STORE CALLER REGS
|
||||
LM 1,2,0(1) R1 -> CCYY, R2 -> DOUBLE-WORD WORK AREA
|
||||
PACK 0(8,2),0(4,1) PACK CCYY INTO WORK AREA
|
||||
CVB 0,0(2) CONVERT TO BINARY (R0 = CCYY)
|
||||
SRDL 0,32 R0|R1 = CCYY
|
||||
LA 2,100 R2 = 100
|
||||
DR 0,2 DIVIDE CCYY BY 100: R0 = YY, R1 = CC
|
||||
LTR 0,0 YY = 0? IF CCYY DIV BY 100, LY IFF DIV BY 400
|
||||
BZ A YES: R0|R1 = CC; CCYY DIV BY 100, TEST CC
|
||||
SRDL 0,32 NO: R0|R1 = YY; CCYY NOT DIV BY 100, TEST YY
|
||||
A LA 2,4 DIVISOR = 4; DIVIDEND = YY, OR DIV BY 100 CC
|
||||
DR 0,2 DIVIDE BY 4: R0 = REMAINDER, R1 = QUOTIENT
|
||||
LR 15,0 LOAD REMAINDER: IF 0, THEN LEAP YEAR
|
||||
LM 0,12,20(13) RESTORE REGS
|
||||
BR 14
|
||||
END
|
||||
44
Task/Leap-year/68000-Assembly/leap-year.68000
Normal file
44
Task/Leap-year/68000-Assembly/leap-year.68000
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
;Example
|
||||
move.l #2018,d0
|
||||
bsr leap_year
|
||||
addi.l #28,d1 ; # days in February 2018
|
||||
rts
|
||||
; Leap Year
|
||||
;
|
||||
; Input
|
||||
; d0=year
|
||||
;
|
||||
; Output
|
||||
; d1=1 if leap year, 0 if not leap year
|
||||
; zero flag clear if leap year, set if not
|
||||
;
|
||||
leap_year:
|
||||
cmpi.l #1752,d0
|
||||
ble.s not_leap_year
|
||||
|
||||
move.l d0,d1
|
||||
lsr.l #1,d1
|
||||
bcs.s not_leap_year
|
||||
lsr.l #1,d1
|
||||
bcs.s not_leap_year
|
||||
|
||||
; If we got here, year is divisible by 4.
|
||||
move.l d0,d1
|
||||
divu #100,d1
|
||||
swap d1
|
||||
tst.w d1
|
||||
bne.s is_leap_year
|
||||
|
||||
; If we got here, year is divisible by 100.
|
||||
move.l d0,d1
|
||||
divu #400,d1
|
||||
swap d1
|
||||
tst.w d1
|
||||
bne.s not_leap_year
|
||||
|
||||
is_leap_year:
|
||||
moveq.l #1,d1
|
||||
rts
|
||||
not_leap_year:
|
||||
moveq.l #0,d1
|
||||
rts
|
||||
61
Task/Leap-year/8080-Assembly/leap-year.8080
Normal file
61
Task/Leap-year/8080-Assembly/leap-year.8080
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
org 100h
|
||||
jmp test
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Check if a year is a leap year.
|
||||
;; Input: HL = year.
|
||||
;; Output: Carry flag set if HL is a leap year.
|
||||
;; Registers used: all.
|
||||
leap: mvi a,3 ; Divisible by 4?
|
||||
ana l ; If not, not a leap year,
|
||||
rnz ; Return w/carry cleared
|
||||
mvi b,2 ; Divide by 4 (shift right 2)
|
||||
leapdiv4: mov a,h
|
||||
rar
|
||||
mov h,a
|
||||
mov a,l
|
||||
rar
|
||||
mov l,a
|
||||
dcr b
|
||||
jnz leapdiv4
|
||||
lxi b,-1 ; Divide by 25 using subtraction
|
||||
lxi d,-25
|
||||
leapdiv25: inx b ; Keep quotient in BC
|
||||
dad d
|
||||
jc leapdiv25
|
||||
mov a,e ; If so, L==E afterwards.
|
||||
xra l ; (High byte is always FF.)
|
||||
stc ; Set carry, and
|
||||
rnz ; return if not divisible.
|
||||
mvi a,3 ; Is this divisble by 4?
|
||||
ana c
|
||||
sui 1 ; Set carry if so.
|
||||
ret
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Test code: get year from CP/M command line and see
|
||||
;; if it is a leap year.
|
||||
test: lxi b,5Dh ; First char of "file name"
|
||||
lxi h,0 ; Accumulator
|
||||
digit: ldax b ; Get character
|
||||
sui '0' ; ASCII digit
|
||||
jc getleap ; Not valid digit = done
|
||||
cpi 10
|
||||
jnc getleap ; Not valid digit = done
|
||||
dad h ; HL *= 10
|
||||
mov d,h
|
||||
mov e,l
|
||||
dad h
|
||||
dad h
|
||||
dad d
|
||||
mvi d,0 ; Plus digit
|
||||
mov e,a
|
||||
dad d
|
||||
inx b ; Next character
|
||||
jmp digit
|
||||
getleap: call leap ; Is HL a leap year?
|
||||
lxi d,no ; No,
|
||||
jnc out ; unless carry is set,
|
||||
lxi d,yes ; then it is a leap year.
|
||||
out: mvi c,9
|
||||
jmp 5
|
||||
no: db 'NOT '
|
||||
yes: db 'LEAP YEAR.$'
|
||||
14
Task/Leap-year/ALGOL-60/leap-year.alg
Normal file
14
Task/Leap-year/ALGOL-60/leap-year.alg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
begin
|
||||
integer year;
|
||||
|
||||
integer procedure mod(i,j); value i,j; integer i,j;
|
||||
mod:=i-(i div j)*j;
|
||||
|
||||
boolean procedure isLeapYear(year); value year; integer year;
|
||||
isLeapYear:=mod(year,400)=0 or (mod(year,4)=0 and mod(year,100) notequal 0);
|
||||
|
||||
for year := 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1999, 2000, 2001, 2002, 2003, 2004 do begin
|
||||
outinteger(1,year);
|
||||
if isLeapYear(year) then outstring(1,"True\n") else outstring(1, "False\n")
|
||||
end for year
|
||||
end
|
||||
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
|
||||
)
|
||||
43
Task/Leap-year/ALGOL-M/leap-year.alg
Normal file
43
Task/Leap-year/ALGOL-M/leap-year.alg
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
BEGIN
|
||||
|
||||
% COMPUTE P MOD Q %
|
||||
INTEGER FUNCTION MOD(P, Q);
|
||||
INTEGER P, Q;
|
||||
BEGIN
|
||||
MOD := P - Q * (P / Q);
|
||||
END;
|
||||
|
||||
% RETURN 1 IF Y IS A LEAP YEAR, OTHERWISE 0 %
|
||||
INTEGER FUNCTION ISLEAP(Y);
|
||||
INTEGER Y;
|
||||
BEGIN
|
||||
IF MOD(Y,4) <> 0 THEN % QUICK EXIT IN MOST CASES %
|
||||
ISLEAP := 0
|
||||
ELSE IF MOD(Y,400) = 0 THEN
|
||||
ISLEAP := 1
|
||||
ELSE IF MOD(Y,100) = 0 THEN
|
||||
ISLEAP := 0
|
||||
ELSE % NON-CENTURY DIVISIBLE BY 4 %
|
||||
ISLEAP := 1;
|
||||
END;
|
||||
|
||||
% EXERCISE THE FUNCTION %
|
||||
INTEGER Y;
|
||||
WRITE("TEST OF CENTURY YEARS");
|
||||
FOR Y := 1600 STEP 100 UNTIL 2000 DO
|
||||
BEGIN
|
||||
IF ISLEAP(Y) <> 0 THEN
|
||||
WRITE(Y, " IS A LEAP YEAR")
|
||||
ELSE
|
||||
WRITE(Y, " IS NOT A LEAP YEAR");
|
||||
END;
|
||||
WRITE("TEST OF CURRENT DECADE");
|
||||
FOR Y := 2010 STEP 1 UNTIL 2020 DO
|
||||
BEGIN
|
||||
IF ISLEAP(Y) <> 0 THEN
|
||||
WRITE(Y, " IS A LEAP YEAR")
|
||||
ELSE
|
||||
WRITE(Y, " IS NOT A LEAP YEAR");
|
||||
END;
|
||||
|
||||
END
|
||||
16
Task/Leap-year/ALGOL-W/leap-year.alg
Normal file
16
Task/Leap-year/ALGOL-W/leap-year.alg
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
begin
|
||||
% returns true if year is a leap year, false otherwise %
|
||||
% assumes year is in the Gregorian Calendar %
|
||||
logical procedure isLeapYear ( integer value year ) ;
|
||||
year rem 400 = 0 or ( year rem 4 = 0 and year rem 100 not = 0 );
|
||||
|
||||
% some test cases %
|
||||
for year := 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1999, 2000, 2001, 2002, 2003, 2004 do begin
|
||||
write( i_w := 1, s_w := 0
|
||||
, year
|
||||
, " is "
|
||||
, if isLeapYear( year ) then "" else "not "
|
||||
, " a leap year"
|
||||
)
|
||||
end for_year
|
||||
end.
|
||||
3
Task/Leap-year/APL/leap-year-1.apl
Normal file
3
Task/Leap-year/APL/leap-year-1.apl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
∇ z←Leap year
|
||||
Z←(0=4|year)∧(0=400|year)∨~0=100|year
|
||||
∇
|
||||
3
Task/Leap-year/APL/leap-year-2.apl
Normal file
3
Task/Leap-year/APL/leap-year-2.apl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
∇ z←Leap year
|
||||
z←0≠.=400 100 4∘.|year
|
||||
∇
|
||||
1
Task/Leap-year/APL/leap-year-3.apl
Normal file
1
Task/Leap-year/APL/leap-year-3.apl
Normal file
|
|
@ -0,0 +1 @@
|
|||
Leap←0≠.=400 100 4∘.|⊢
|
||||
1
Task/Leap-year/APL/leap-year-4.apl
Normal file
1
Task/Leap-year/APL/leap-year-4.apl
Normal file
|
|
@ -0,0 +1 @@
|
|||
Leap←0⎕DT,∘2 29¨
|
||||
1
Task/Leap-year/APL/leap-year-5.apl
Normal file
1
Task/Leap-year/APL/leap-year-5.apl
Normal file
|
|
@ -0,0 +1 @@
|
|||
Leap 1899 1900 1901 1902 1903 1904 1905 1999 2000 2001 2002 2003 2004
|
||||
1
Task/Leap-year/APL/leap-year-6.apl
Normal file
1
Task/Leap-year/APL/leap-year-6.apl
Normal file
|
|
@ -0,0 +1 @@
|
|||
0 0 0 0 0 1 0 0 1 0 0 0 1
|
||||
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 )
|
||||
}
|
||||
30
Task/Leap-year/Action-/leap-year.action
Normal file
30
Task/Leap-year/Action-/leap-year.action
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
BYTE FUNC IsLeapYear(CARD year)
|
||||
IF year MOD 100=0 THEN
|
||||
IF year MOD 400=0 THEN
|
||||
RETURN (1)
|
||||
ELSE
|
||||
RETURN (0)
|
||||
FI
|
||||
FI
|
||||
|
||||
IF year MOD 4=0 THEN
|
||||
RETURN (1)
|
||||
FI
|
||||
RETURN (0)
|
||||
|
||||
PROC Main()
|
||||
CARD ARRAY t=[1900 1901 2000 2001 2004 2020 2021]
|
||||
BYTE i,leap
|
||||
CARD year
|
||||
|
||||
FOR i=0 TO 6
|
||||
DO
|
||||
year=t(i)
|
||||
leap=IsLeapYear(year)
|
||||
IF leap=0 THEN
|
||||
PrintF("%U is not a leap year%E",year)
|
||||
ELSE
|
||||
PrintF("%U is a leap year%E",year)
|
||||
FI
|
||||
OD
|
||||
RETURN
|
||||
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);
|
||||
}
|
||||
35
Task/Leap-year/Ada/leap-year.ada
Normal file
35
Task/Leap-year/Ada/leap-year.ada
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
-- 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;
|
||||
|
||||
|
||||
-- An enhanced, more efficient version:
|
||||
-- This version only does the 2 bit comparison (rem 4) if false.
|
||||
-- It then checks rem 16 (a 4 bit comparison), and only if those are not
|
||||
-- conclusive, calls rem 100, which is the most expensive operation.
|
||||
-- I failed to be convinced of the accuracy of the algorithm at first,
|
||||
-- so I rephrased it below.
|
||||
-- FYI: 400 is evenly divisible by 16 whereas 100,200 and 300 are not. Ergo, the
|
||||
-- set of integers evenly divisible by 16 and 100 are all evenly divisible by 400.
|
||||
-- 1. If a year is not divisible by 4 => not a leap year. Skip other checks.
|
||||
-- 2. If a year is evenly divisible by 16, it is either evenly divisible by 400 or
|
||||
-- not evenly divisible by 100 => leap year. Skip further checks.
|
||||
-- 3. If a year evenly divisible by 100 => not a leap year.
|
||||
-- 4. Otherwise a leap year.
|
||||
|
||||
function Is_Leap_Year (Year : Integer) return Boolean is
|
||||
begin
|
||||
return (Year rem 4 = 0) and then ((Year rem 16 = 0) or else (Year rem 100 /= 0));
|
||||
end Is_Leap_Year;
|
||||
|
||||
|
||||
|
||||
-- To improve speed a bit more, use with
|
||||
pragma Inline (Is_Leap_Year);
|
||||
5
Task/Leap-year/AppleScript/leap-year.applescript
Normal file
5
Task/Leap-year/AppleScript/leap-year.applescript
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
on leap_year(y)
|
||||
return y mod 4 is equal to 0 and (y mod 100 is not equal to 0 or y mod 400 is equal to 0)
|
||||
end leap_year
|
||||
|
||||
leap_year(1900)
|
||||
1
Task/Leap-year/Applesoft-BASIC/leap-year.basic
Normal file
1
Task/Leap-year/Applesoft-BASIC/leap-year.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
FOR Y = 1750 TO 2021: PRINT MID$ ( STR$ (Y) + " ",1,5 * (Y / 4 = INT (Y / 4)) * ((Y / 100 < > INT (Y / 100)) + (Y / 400 = INT (Y / 400))));: NEXT
|
||||
3
Task/Leap-year/Arc/leap-year-1.arc
Normal file
3
Task/Leap-year/Arc/leap-year-1.arc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(= leap? (fn (year)
|
||||
(if (and (is 0 (mod year 4)) (isnt 0 (mod year 100))) year
|
||||
(unless (< 0 (+ (mod year 100) (mod year 400))) year))))
|
||||
2
Task/Leap-year/Arc/leap-year-2.arc
Normal file
2
Task/Leap-year/Arc/leap-year-2.arc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(map [leap? _] '(1900 1904 2000 2019 2020 2100))
|
||||
;; => '( 1904 2000 2020 )
|
||||
8
Task/Leap-year/Arturo/leap-year.arturo
Normal file
8
Task/Leap-year/Arturo/leap-year.arturo
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
years: [
|
||||
1600 1660 1724 1788 1848 1912 1972
|
||||
2032 2092 2156 2220 2280 2344 2348
|
||||
1698 1699 1700 1750 1800 1810 1900
|
||||
1901 1973 2100 2107 2200 2203 2289
|
||||
]
|
||||
|
||||
print select years => leap?
|
||||
8
Task/Leap-year/AutoHotkey/leap-year-1.ahk
Normal file
8
Task/Leap-year/AutoHotkey/leap-year-1.ahk
Normal 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)
|
||||
6
Task/Leap-year/AutoHotkey/leap-year-2.ahk
Normal file
6
Task/Leap-year/AutoHotkey/leap-year-2.ahk
Normal 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"
|
||||
12
Task/Leap-year/AutoIt/leap-year.autoit
Normal file
12
Task/Leap-year/AutoIt/leap-year.autoit
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
; AutoIt Version: 3.3.8.1
|
||||
$Year = 2012
|
||||
$sNot = " not"
|
||||
|
||||
If IsLeapYear($Year) Then $sNot = ""
|
||||
ConsoleWrite ($Year & " is" & $sNot & " a leap year." & @LF)
|
||||
|
||||
Func IsLeapYear($_year)
|
||||
Return Not Mod($_year, 4) And (Mod($_year, 100) Or Not Mod($_year, 400))
|
||||
EndFunc
|
||||
|
||||
; == But it exists the standard UDF "Date.au3" with this function: "_IsLeapYear($Year)"
|
||||
20
Task/Leap-year/BASIC256/leap-year.basic
Normal file
20
Task/Leap-year/BASIC256/leap-year.basic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# year is a BASIC-256 keyword
|
||||
function leapyear(year_)
|
||||
if (year_ mod 4) <> 0 then return FALSE
|
||||
if (year_ mod 100) = 0 and (year_ mod 400) <> 0 then return FALSE
|
||||
return TRUE
|
||||
end function
|
||||
|
||||
for year_ = 1800 to 2900 step 100
|
||||
print year_;
|
||||
if leapyear(year_) then print " is a leap year" else print " is not a leap year"
|
||||
next year_
|
||||
|
||||
print
|
||||
|
||||
for year_ = 2012 to 2031
|
||||
print year_;
|
||||
if leapyear(year_) = TRUE then print " = leap "; else print " = no ";
|
||||
if (year_ mod 4) = 3 then print ""
|
||||
next year_
|
||||
end
|
||||
12
Task/Leap-year/BBC-BASIC/leap-year-1.basic
Normal file
12
Task/Leap-year/BBC-BASIC/leap-year-1.basic
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))
|
||||
5
Task/Leap-year/BBC-BASIC/leap-year-2.basic
Normal file
5
Task/Leap-year/BBC-BASIC/leap-year-2.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
DEFFNleap(yr%)
|
||||
IF yr% MOD 4 THEN =FALSE
|
||||
IF yr% MOD 400 ELSE =TRUE
|
||||
IF yr% MOD 100 ELSE =FALSE
|
||||
=TRUE
|
||||
11
Task/Leap-year/BCPL/leap-year.bcpl
Normal file
11
Task/Leap-year/BCPL/leap-year.bcpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
get "libhdr"
|
||||
|
||||
let leap(year) = year rem 400 = 0 | (year rem 4 = 0 & year rem 100 ~= 0)
|
||||
|
||||
let start() be
|
||||
$( let years = table 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1999,
|
||||
2000, 2001, 2002, 2003, 2004, 2021, 2022
|
||||
for i = 0 to 14 do
|
||||
writef("%N %S a leap year.*N",
|
||||
years!i, leap(years!i) -> "is", "is not")
|
||||
$)
|
||||
12
Task/Leap-year/BaCon/leap-year.bacon
Normal file
12
Task/Leap-year/BaCon/leap-year.bacon
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
' Leap year
|
||||
FUNCTION leapyear(NUMBER y) TYPE NUMBER
|
||||
RETURN IIF(MOD(y, 4) = 0, IIF(MOD(y, 16) = 0, IIF(MOD(y, 100) != 0, TRUE, FALSE), TRUE), FALSE)
|
||||
END FUNCTION
|
||||
|
||||
READ y
|
||||
WHILE y != 0
|
||||
PRINT y, ": ", IIF$(leapyear(y), "", "not a "), "leapyear"
|
||||
READ y
|
||||
WEND
|
||||
|
||||
DATA 1600, 1700, 1800, 1900, 1901, 1996, 2000, 2001, 2004, 0
|
||||
29
Task/Leap-year/Batch-File/leap-year.bat
Normal file
29
Task/Leap-year/Batch-File/leap-year.bat
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
@echo off
|
||||
|
||||
::The Main Thing...
|
||||
for %%x in (1900 2046 2012 1600 1800 2031 1952) do (
|
||||
call :leap %%x
|
||||
)
|
||||
echo.
|
||||
pause
|
||||
exit/b
|
||||
::/The Main Thing...
|
||||
|
||||
::The Function...
|
||||
:leap
|
||||
set year=%1
|
||||
set /a op1=%year%%%4
|
||||
set /a op2=%year%%%100
|
||||
set /a op3=%year%%%400
|
||||
if not "%op1%"=="0" (goto :no)
|
||||
if not "%op2%"=="0" (goto :yes)
|
||||
if not "%op3%"=="0" (goto :no)
|
||||
:yes
|
||||
echo.
|
||||
echo %year% is a leap year.
|
||||
goto :EOF
|
||||
:no
|
||||
echo.
|
||||
echo %year% is NOT a leap year.
|
||||
goto :EOF
|
||||
::/The Function...
|
||||
5
Task/Leap-year/Bc/leap-year.bc
Normal file
5
Task/Leap-year/Bc/leap-year.bc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
define l(y) {
|
||||
if (y % 100 == 0) y /= 100
|
||||
if (y % 4 == 0) return(1)
|
||||
return(0)
|
||||
}
|
||||
5
Task/Leap-year/Befunge/leap-year.bf
Normal file
5
Task/Leap-year/Befunge/leap-year.bf
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
0"2("*:3-:1-:2-:"^"-v<
|
||||
v*%"d"\!%4::,,"is".:<|
|
||||
>\45*:*%!+#v_ "ton"vv<
|
||||
v"ear."+550<,,,,*84<$#
|
||||
>"y pael a ">:#,_$:#@^
|
||||
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")
|
||||
)
|
||||
)
|
||||
& ;
|
||||
11
Task/Leap-year/C++/leap-year.cpp
Normal file
11
Task/Leap-year/C++/leap-year.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <iostream>
|
||||
|
||||
bool is_leap_year(int year) {
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
for (auto year : {1900, 1994, 1996, 1997, 2000}) {
|
||||
std::cout << year << (is_leap_year(year) ? " is" : " is not") << " a leap year.\n";
|
||||
}
|
||||
}
|
||||
14
Task/Leap-year/C-sharp/leap-year.cs
Normal file
14
Task/Leap-year/C-sharp/leap-year.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
foreach (var year in new[] { 1900, 1994, 1996, DateTime.Now.Year })
|
||||
{
|
||||
Console.WriteLine("{0} is {1}a leap year.",
|
||||
year,
|
||||
DateTime.IsLeapYear(year) ? string.Empty : "not ");
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Task/Leap-year/C/leap-year.c
Normal file
20
Task/Leap-year/C/leap-year.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int is_leap_year(unsigned year)
|
||||
{
|
||||
return !(year & (year % 100 ? 3 : 15));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const unsigned test_case[] = {
|
||||
1900, 1994, 1996, 1997, 2000, 2024, 2025, 2026, 2100
|
||||
};
|
||||
const unsigned n = sizeof test_case / sizeof test_case[0];
|
||||
|
||||
for (unsigned i = 0; i != n; ++i) {
|
||||
unsigned year = test_case[i];
|
||||
printf("%u is %sa leap year.\n", year, is_leap_year(year) ? "" : "not ");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
16
Task/Leap-year/CLU/leap-year.clu
Normal file
16
Task/Leap-year/CLU/leap-year.clu
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
is_leap_year = proc (year: int) returns (bool)
|
||||
return(year//400 =0 cor (year//4 = 0 cand year//100 ~= 0))
|
||||
end is_leap_year
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
years: sequence[int] := sequence[int]$
|
||||
[1899, 1900, 1901, 1902, 1903, 1904, 1905, 1999,
|
||||
2000, 2001, 2002, 2003, 2004, 2021, 2022]
|
||||
|
||||
for year: int in sequence[int]$elements(years) do
|
||||
stream$puts(po, int$unparse(year) || " is ")
|
||||
if ~is_leap_year(year) then stream$puts(po, "not ") end
|
||||
stream$putl(po, "a leap year.")
|
||||
end
|
||||
end start_up
|
||||
29
Task/Leap-year/COBOL/leap-year-1.cobol
Normal file
29
Task/Leap-year/COBOL/leap-year-1.cobol
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. leap-year.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 examples VALUE "19001994199619972000".
|
||||
03 year PIC 9(4) OCCURS 5 TIMES
|
||||
INDEXED BY year-index.
|
||||
|
||||
01 remainders.
|
||||
03 400-rem PIC 9(4).
|
||||
03 100-rem PIC 9(4).
|
||||
03 4-rem PIC 9(4).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
PERFORM VARYING year-index FROM 1 BY 1 UNTIL 5 < year-index
|
||||
MOVE FUNCTION MOD(year (year-index), 400) TO 400-rem
|
||||
MOVE FUNCTION MOD(year (year-index), 100) TO 100-rem
|
||||
MOVE FUNCTION MOD(year (year-index), 4) TO 4-rem
|
||||
|
||||
IF 400-rem = 0 OR ((100-rem NOT = 0) AND 4-rem = 0)
|
||||
DISPLAY year (year-index) " is a leap year."
|
||||
ELSE
|
||||
DISPLAY year (year-index) " is not a leap year."
|
||||
END-IF
|
||||
END-PERFORM
|
||||
|
||||
GOBACK
|
||||
.
|
||||
33
Task/Leap-year/COBOL/leap-year-2.cobol
Normal file
33
Task/Leap-year/COBOL/leap-year-2.cobol
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
program-id. leap-yr.
|
||||
*> Given a year, where 1601 <= year <= 9999
|
||||
*> Determine if the year is a leap year
|
||||
data division.
|
||||
working-storage section.
|
||||
1 input-year pic 9999.
|
||||
1 binary.
|
||||
2 int-date pic 9(8).
|
||||
2 cal-mo-day pic 9(4).
|
||||
procedure division.
|
||||
display "Enter calendar year (1601 thru 9999): "
|
||||
with no advancing
|
||||
accept input-year
|
||||
if input-year >= 1601 and <= 9999
|
||||
then
|
||||
*> if the 60th day of a year is Feb 29
|
||||
*> then the year is a leap year
|
||||
compute int-date = function integer-of-day
|
||||
( input-year * 1000 + 60 )
|
||||
compute cal-mo-day = function mod (
|
||||
(function date-of-integer ( int-date )) 10000 )
|
||||
display "Year " input-year space with no advancing
|
||||
if cal-mo-day = 229
|
||||
display "is a leap year"
|
||||
else
|
||||
display "is NOT a leap year"
|
||||
end-if
|
||||
else
|
||||
display "Input date is not within range"
|
||||
end-if
|
||||
stop run
|
||||
.
|
||||
end program leap-yr.
|
||||
14
Task/Leap-year/Chipmunk-Basic/leap-year.basic
Normal file
14
Task/Leap-year/Chipmunk-Basic/leap-year.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 rem Leap year
|
||||
20 for i% = 1 to 5
|
||||
30 read year%
|
||||
40 print year%;"is ";
|
||||
50 if isleapyear(year%) = 0 then print "not "; else print "";
|
||||
60 print "a leap year."
|
||||
70 next i%
|
||||
80 end
|
||||
|
||||
200 data 1900,1994,1996,1997,2000
|
||||
|
||||
400 sub isleapyear(y%)
|
||||
410 isleapyear = ((y% mod 4 = 0) and (y% mod 100 <> 0)) or (y% mod 400 = 0)
|
||||
420 end sub
|
||||
2
Task/Leap-year/Clipper/leap-year.clipper
Normal file
2
Task/Leap-year/Clipper/leap-year.clipper
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Function IsLeapYear( nYear )
|
||||
Return Iif( nYear%100 == 0, (nYear%400 == 0), (nYear%4 == 0) )
|
||||
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)))))
|
||||
1
Task/Leap-year/Commodore-BASIC/leap-year.basic
Normal file
1
Task/Leap-year/Commodore-BASIC/leap-year.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
10 DEF FNLY(Y)=(Y/4=INT(Y/4))*((Y/100<>INT(Y/100))+(Y/400=INT(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))))
|
||||
29
Task/Leap-year/Component-Pascal/leap-year.pas
Normal file
29
Task/Leap-year/Component-Pascal/leap-year.pas
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
MODULE LeapYear;
|
||||
IMPORT StdLog, Strings, Args;
|
||||
|
||||
PROCEDURE IsLeapYear(year: INTEGER): BOOLEAN;
|
||||
BEGIN
|
||||
IF year MOD 4 # 0 THEN
|
||||
RETURN FALSE
|
||||
ELSE
|
||||
IF year MOD 100 = 0 THEN
|
||||
IF year MOD 400 = 0 THEN RETURN TRUE ELSE RETURN FALSE END
|
||||
ELSE
|
||||
RETURN TRUE
|
||||
END
|
||||
END
|
||||
END IsLeapYear;
|
||||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
p: Args.Params;
|
||||
year,done,i: INTEGER;
|
||||
BEGIN
|
||||
Args.Get(p);
|
||||
FOR i := 0 TO p.argc - 1 DO
|
||||
Strings.StringToInt(p.args[i],year,done);
|
||||
StdLog.Int(year);StdLog.String(":>");StdLog.Bool(IsLeapYear(year));StdLog.Ln
|
||||
END;
|
||||
|
||||
END Do;
|
||||
END LeapYear.
|
||||
3
Task/Leap-year/Crystal/leap-year.crystal
Normal file
3
Task/Leap-year/Crystal/leap-year.crystal
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
p Time.leap_year?(2020)
|
||||
p Time.leap_year?(2021)
|
||||
p Time.leap_year?(2022)
|
||||
13
Task/Leap-year/D/leap-year-1.d
Normal file
13
Task/Leap-year/D/leap-year-1.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));
|
||||
}
|
||||
8
Task/Leap-year/D/leap-year-2.d
Normal file
8
Task/Leap-year/D/leap-year-2.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import std.datetime;
|
||||
|
||||
void main() {
|
||||
assert(yearIsLeapYear(1724));
|
||||
assert(!yearIsLeapYear(1973));
|
||||
assert(!Date(1900, 1, 1).isLeapYear);
|
||||
assert(DateTime(2000, 1, 1).isLeapYear);
|
||||
}
|
||||
21
Task/Leap-year/DWScript/leap-year.dw
Normal file
21
Task/Leap-year/DWScript/leap-year.dw
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);
|
||||
9
Task/Leap-year/Dart/leap-year.dart
Normal file
9
Task/Leap-year/Dart/leap-year.dart
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class Leap {
|
||||
bool leapYear(num year) {
|
||||
return (year % 400 == 0) || (( year % 100 != 0) && (year % 4 == 0));
|
||||
|
||||
bool isLeapYear(int year) =>
|
||||
(year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
|
||||
// Source: https://api.flutter.dev/flutter/quiver.time/isLeapYear.html
|
||||
}
|
||||
}
|
||||
24
Task/Leap-year/Dc/leap-year.dc
Normal file
24
Task/Leap-year/Dc/leap-year.dc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
[0q]s0
|
||||
[1q]s1
|
||||
|
||||
[ S. [ l. 4% 0!=0 ## if y % 4: return 0
|
||||
l. 100% 0!=1 ## if y % 100: return 1
|
||||
l. 400% 0!=0 ## if y % 400: return 0
|
||||
1 ## return 1
|
||||
]x s.L.
|
||||
]sL ## L = isleapYear()
|
||||
|
||||
[ Sy
|
||||
lyn [ is ]P
|
||||
ly lLx
|
||||
[not ] 0:y
|
||||
[ ] 1:y
|
||||
;yP
|
||||
[a leap year]P AP
|
||||
OsyLyo
|
||||
]sT ## T = testYear()
|
||||
|
||||
1988 lTx
|
||||
1989 lTx
|
||||
1900 lTx
|
||||
2000 lTx
|
||||
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.
|
||||
15
Task/Leap-year/Draco/leap-year.draco
Normal file
15
Task/Leap-year/Draco/leap-year.draco
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
proc nonrec leap_year(word year) bool:
|
||||
year%400=0 or (year%4=0 and year%100/=0)
|
||||
corp
|
||||
|
||||
proc nonrec main() void:
|
||||
[15]word years = (1899, 1900, 1901, 1902, 1903, 1904, 1905, 1999,
|
||||
2000, 2001, 2002, 2003, 2004, 2021, 2022);
|
||||
word i;
|
||||
|
||||
for i from 0 upto 14 do
|
||||
writeln(years[i],
|
||||
if leap_year(years[i]) then " is " else " is not " fi,
|
||||
"a leap year.")
|
||||
od
|
||||
corp
|
||||
9
Task/Leap-year/Dyalect/leap-year.dyalect
Normal file
9
Task/Leap-year/Dyalect/leap-year.dyalect
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
func isLeap(y) {
|
||||
if y % 100 == 0 {
|
||||
y % 400 == 0
|
||||
} else {
|
||||
y % 4 == 0
|
||||
}
|
||||
}
|
||||
|
||||
print(isLeap(1984))
|
||||
17
Task/Leap-year/ERRE/leap-year.erre
Normal file
17
Task/Leap-year/ERRE/leap-year.erre
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
PROGRAM LEAP_YEAR
|
||||
|
||||
FUNCTION LEAP(YR%)
|
||||
LEAP=(YR% MOD 4=0) AND ((YR% MOD 400=0) OR (YR% MOD 100<>0))
|
||||
END FUNCTION
|
||||
|
||||
BEGIN
|
||||
LOOP
|
||||
INPUT("Enter a year: ",year%)
|
||||
EXIT IF YEAR%=0
|
||||
IF LEAP(year%) THEN
|
||||
PRINT(year%;" is a leap year")
|
||||
ELSE
|
||||
PRINT(year%;" is not a leap year")
|
||||
END IF
|
||||
END LOOP
|
||||
END PROGRAM
|
||||
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
|
||||
2
Task/Leap-year/Elixir/leap-year.elixir
Normal file
2
Task/Leap-year/Elixir/leap-year.elixir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
leap_year? = fn(year) -> :calendar.is_leap_year(year) end
|
||||
IO.inspect for y <- 2000..2020, leap_year?.(y), do: y
|
||||
4
Task/Leap-year/Emacs-Lisp/leap-year.l
Normal file
4
Task/Leap-year/Emacs-Lisp/leap-year.l
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(defun leap-year-p (year)
|
||||
(apply (lambda (a b c) (or a (and (not b) c)))
|
||||
(mapcar (lambda (n) (zerop (mod year n)))
|
||||
'(400 100 4))))
|
||||
4
Task/Leap-year/Erlang/leap-year.erl
Normal file
4
Task/Leap-year/Erlang/leap-year.erl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
-module(gregorian).
|
||||
-export([leap/1]).
|
||||
|
||||
leap( Year ) -> calendar:is_leap_year( Year ).
|
||||
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
|
||||
1
Task/Leap-year/Excel/leap-year-1.excel
Normal file
1
Task/Leap-year/Excel/leap-year-1.excel
Normal file
|
|
@ -0,0 +1 @@
|
|||
=IF(OR(NOT(MOD(A1,400)),AND(NOT(MOD(A1,4)),MOD(A1,100))),"Leap Year","Not a Leap Year")
|
||||
10
Task/Leap-year/Excel/leap-year-2.excel
Normal file
10
Task/Leap-year/Excel/leap-year-2.excel
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
ISLEAPYEAR
|
||||
=LAMBDA(y,
|
||||
OR(
|
||||
0 = MOD(y, 400),
|
||||
AND(
|
||||
0 = MOD(y, 4),
|
||||
0 <> MOD(y, 100)
|
||||
)
|
||||
)
|
||||
)
|
||||
5
Task/Leap-year/F-Sharp/leap-year.fs
Normal file
5
Task/Leap-year/F-Sharp/leap-year.fs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let isLeapYear = System.DateTime.IsLeapYear
|
||||
assert isLeapYear 1996
|
||||
assert isLeapYear 2000
|
||||
assert not (isLeapYear 2001)
|
||||
assert not (isLeapYear 1900)
|
||||
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? .
|
||||
1
Task/Leap-year/Fermat/leap-year.fermat
Normal file
1
Task/Leap-year/Fermat/leap-year.fermat
Normal file
|
|
@ -0,0 +1 @@
|
|||
Function IsLeap(y) = if y|4>0 then 0 else if y|100=0 and y|400>0 then 0 else 1 fi fi.
|
||||
4
Task/Leap-year/Forth/leap-year-1.fth
Normal file
4
Task/Leap-year/Forth/leap-year-1.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= ;
|
||||
1
Task/Leap-year/Forth/leap-year-2.fth
Normal file
1
Task/Leap-year/Forth/leap-year-2.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
: leap-year? dup 4 mod 0= over 16 mod 0= rot 25 mod 0= not or and ;
|
||||
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
|
||||
42
Task/Leap-year/FreeBASIC/leap-year.basic
Normal file
42
Task/Leap-year/FreeBASIC/leap-year.basic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
' version 23-06-2015
|
||||
' compile with: fbc -s console
|
||||
|
||||
#Ifndef TRUE ' define true and false for older freebasic versions
|
||||
#Define FALSE 0
|
||||
#Define TRUE Not FALSE
|
||||
#EndIf
|
||||
|
||||
Function leapyear(Year_ As Integer) As Integer
|
||||
|
||||
If (Year_ Mod 4) <> 0 Then Return FALSE
|
||||
If (Year_ Mod 100) = 0 AndAlso (Year_ Mod 400) <> 0 Then Return FALSE
|
||||
Return TRUE
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
' year is a FreeBASIC keyword
|
||||
Dim As Integer Year_
|
||||
|
||||
For Year_ = 1800 To 2900 Step 100
|
||||
Print Year_; IIf(leapyear(Year_), " is a leap year", " is not a leap year")
|
||||
Next
|
||||
|
||||
Print : Print
|
||||
|
||||
For Year_ = 2012 To 2031
|
||||
Print Year_;
|
||||
If leapyear(Year_) = TRUE Then
|
||||
Print " = leap",
|
||||
Else
|
||||
Print " = no",
|
||||
End If
|
||||
If year_ Mod 4 = 3 Then Print ' lf/cr
|
||||
Next
|
||||
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
52
Task/Leap-year/FutureBasic/leap-year.basic
Normal file
52
Task/Leap-year/FutureBasic/leap-year.basic
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
window 1
|
||||
|
||||
// In-line C function to generate random number in range
|
||||
BeginCFunction
|
||||
long randomInRange( long min, long max ) {
|
||||
int i = (arc4random()%(max-min+1))+min;
|
||||
return (long)i;
|
||||
}
|
||||
EndC
|
||||
toolbox fn randomInRange( long min, long max ) = long
|
||||
|
||||
// Leap year test function
|
||||
local fn LeapYear( year as long ) as BOOL
|
||||
BOOL result : result = _false
|
||||
|
||||
if year mod 400 == 0 then result = _true : exit fn
|
||||
if year mod 100 == 0 then result = _false : exit fn
|
||||
if year mod 4 == 0 then result = _true : exit fn
|
||||
if year mod 4 != 0 then result = _false : exit fn
|
||||
end fn = result
|
||||
|
||||
long i, y, knownLeapYear(10)
|
||||
|
||||
// Array of known leap years from 1980 through 2020 for control
|
||||
knownLeapYear(0) = 1980 : knownLeapYear(1) = 1984 : knownLeapYear(2) = 1988
|
||||
knownLeapYear(3) = 1992 : knownLeapYear(4) = 1996 : knownLeapYear(5) = 2000
|
||||
knownLeapYear(6) = 2004 : knownLeapYear(7) = 2008 : knownLeapYear(8) = 2012
|
||||
knownLeapYear(9) = 2016 : knownLeapYear(10) = 2020
|
||||
|
||||
print "Known leap years:"
|
||||
for i = 0 to 9
|
||||
if ( fn LeapYear( knownLeapYear(i) ) == _true )
|
||||
print knownLeapYear(i); " is a leap year."
|
||||
else
|
||||
print knownLeapYear(i); " is a not leap year."
|
||||
end if
|
||||
next
|
||||
|
||||
print
|
||||
|
||||
// Random years from 1980 to 2020 to test
|
||||
print "Check random years:"
|
||||
for i = 0 to 20
|
||||
y = fn randomInRange( 1980, 2020 )
|
||||
if ( fn LeapYear( y ) == _true )
|
||||
print y; " is a leap year."
|
||||
else
|
||||
print y; " is a not leap year."
|
||||
end if
|
||||
next
|
||||
|
||||
HandleEvents
|
||||
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;
|
||||
11
Task/Leap-year/GW-BASIC/leap-year-1.basic
Normal file
11
Task/Leap-year/GW-BASIC/leap-year-1.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10 ' Leap year
|
||||
20 DEF FN ISLEAPYEAR(Y%) = ((Y% MOD 4 = 0) AND (Y% MOD 100 <> 0)) OR (Y% MOD 400 = 0)
|
||||
95 ' *** Test ***
|
||||
100 FOR I% = 1 TO 5
|
||||
110 READ YEAR%
|
||||
120 PRINT YEAR%; "is ";
|
||||
130 IF FN ISLEAPYEAR(YEAR%) = 0 THEN PRINT "not "; ELSE PRINT "";
|
||||
140 PRINT "a leap year."
|
||||
150 NEXT I%
|
||||
160 END
|
||||
200 DATA 1900, 1994, 1996, 1997, 2000
|
||||
10
Task/Leap-year/GW-BASIC/leap-year-2.basic
Normal file
10
Task/Leap-year/GW-BASIC/leap-year-2.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
10 FOR Y = 1750 TO 2021
|
||||
20 GOSUB 1000
|
||||
30 IF L = 1 THEN PRINT Y;" ";
|
||||
40 NEXT Y
|
||||
50 END
|
||||
1000 L = 0
|
||||
1010 IF Y MOD 4 <> 0 THEN RETURN
|
||||
1020 IF Y MOD 100 = 0 AND Y MOD 400 <> 0 THEN RETURN
|
||||
1030 L = 1
|
||||
1040 RETURN
|
||||
11
Task/Leap-year/Gambas/leap-year.gambas
Normal file
11
Task/Leap-year/Gambas/leap-year.gambas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Public Sub Form_Open()
|
||||
Dim dDate As Date
|
||||
Dim siYear As Short = InputBox("Enter a year", "Leap year test")
|
||||
Dim sMessage As String = " is a leap year."
|
||||
|
||||
Try dDate = Date(siYear, 02, 29)
|
||||
If Error Then sMessage = " is not a leap year."
|
||||
|
||||
Message(siYear & sMessage)
|
||||
|
||||
End
|
||||
13
Task/Leap-year/Genie/leap-year.genie
Normal file
13
Task/Leap-year/Genie/leap-year.genie
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[indent=4]
|
||||
/*
|
||||
Leap year, in Genie
|
||||
|
||||
valac leapYear.gs
|
||||
./leapYear
|
||||
*/
|
||||
init
|
||||
years:array of DateYear = {1900, 1994, 1996, 1997, 2000, 2100}
|
||||
|
||||
for year in years
|
||||
status:string = year.is_leap_year() ? "" : "not "
|
||||
stdout.printf("%d is %sa leap year.\n", year, status)
|
||||
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}
|
||||
2
Task/Leap-year/Harbour/leap-year.harbour
Normal file
2
Task/Leap-year/Harbour/leap-year.harbour
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
FUNCTION IsLeapYear( nYear )
|
||||
RETURN iif( nYear % 100 == 0, nYear % 400 == 0, nYear % 4 == 0 )
|
||||
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
|
||||
14
Task/Leap-year/Haskell/leap-year-4.hs
Normal file
14
Task/Leap-year/Haskell/leap-year-4.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import Test.HUnit
|
||||
|
||||
isLeapYear::Int->Bool
|
||||
isLeapYear y
|
||||
| mod y 400 == 0 = True
|
||||
| mod y 100 == 0 = False
|
||||
| mod y 4 == 0 = True
|
||||
| otherwise = False
|
||||
|
||||
tests = TestList[TestCase $ assertEqual "4 is a leap year" True $ isLeapYear 4
|
||||
,TestCase $ assertEqual "1 is not a leap year" False $ isLeapYear 1
|
||||
,TestCase $ assertEqual "64 is a leap year" True $ isLeapYear 64
|
||||
,TestCase $ assertEqual "2000 is a leap year" True $ isLeapYear 2000
|
||||
,TestCase $ assertEqual "1900 is not a leap year" False $ isLeapYear 1900]
|
||||
6
Task/Leap-year/Hy/leap-year.hy
Normal file
6
Task/Leap-year/Hy/leap-year.hy
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(defn leap? [y]
|
||||
(and
|
||||
(= (% y 4) 0)
|
||||
(or
|
||||
(!= (% y 100) 0)
|
||||
(= (% y 400) 0))))
|
||||
9
Task/Leap-year/IS-BASIC/leap-year.basic
Normal file
9
Task/Leap-year/IS-BASIC/leap-year.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
100 PROGRAM "Leapyear.bas"
|
||||
110 FOR I=1990 TO 2020
|
||||
120 IF LEAPY(I) THEN
|
||||
130 PRINT I;"is a leap year."
|
||||
140 ELSE
|
||||
150 PRINT I;"is not a leap year."
|
||||
160 END IF
|
||||
170 NEXT
|
||||
180 DEF LEAPY(Y)=MOD(Y,4)=0 AND MOD(Y,100) OR MOD(Y,400)=0
|
||||
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
|
||||
17
Task/Leap-year/Java/leap-year-1.java
Normal file
17
Task/Leap-year/Java/leap-year-1.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import java.util.GregorianCalendar;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class Leapyear{
|
||||
public static void main(String[] argv){
|
||||
int[] yrs = {1800,1900,1994,1998,1999,2000,2001,2004,2100};
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
for(int year : yrs){
|
||||
System.err.println(MessageFormat.format("The year {0,number,#} is leaper: {1} / {2}.",
|
||||
year, cal.isLeapYear(year), isLeapYear(year)));
|
||||
}
|
||||
|
||||
}
|
||||
public static boolean isLeapYear(int year){
|
||||
return (year % 100 == 0) ? (year % 400 == 0) : (year % 4 == 0);
|
||||
}
|
||||
}
|
||||
8
Task/Leap-year/Java/leap-year-2.java
Normal file
8
Task/Leap-year/Java/leap-year-2.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import java.time.Year;
|
||||
|
||||
public class IsLeap {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Year.isLeap(2004));
|
||||
}
|
||||
}
|
||||
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; };
|
||||
1
Task/Leap-year/Joy/leap-year.joy
Normal file
1
Task/Leap-year/Joy/leap-year.joy
Normal file
|
|
@ -0,0 +1 @@
|
|||
DEFINE leapyear == dup 100 div null rotate choice 4 rem null.
|
||||
2
Task/Leap-year/Jq/leap-year-1.jq
Normal file
2
Task/Leap-year/Jq/leap-year-1.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def leap:
|
||||
. as $y | ($y%4) == 0 and ($y < 1582 or ($y%400) == 0 or ($y%100) != 0);
|
||||
7
Task/Leap-year/Jq/leap-year-2.jq
Normal file
7
Task/Leap-year/Jq/leap-year-2.jq
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def assert(value; f):
|
||||
value as $value
|
||||
| ($value|f) | if . then empty else error("assertion violation: \($value) => \(.)") end;
|
||||
|
||||
((2400, 2012, 2000, 1600, 1500, 1400) | assert(.; leap)),
|
||||
|
||||
((2100, 2014, 1900, 1800, 1700, 1499) | assert(.; leap|not))
|
||||
4
Task/Leap-year/Julia/leap-year.julia
Normal file
4
Task/Leap-year/Julia/leap-year.julia
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
isleap(yr::Integer) = yr % 4 == 0 && (yr < 1582 || yr % 400 == 0 || yr % 100 != 0)
|
||||
|
||||
@assert all(isleap, [2400, 2012, 2000, 1600, 1500, 1400])
|
||||
@assert !any(isleap, [2100, 2014, 1900, 1800, 1700, 1499])
|
||||
4
Task/Leap-year/K/leap-year-1.k
Normal file
4
Task/Leap-year/K/leap-year-1.k
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
lyp:{(+/~x!'4 100 400)!2}
|
||||
|
||||
lyp'1996+!6
|
||||
1 0 0 0 1 0
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue