Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Leap_year
note: Date and time

View 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>

View file

@ -0,0 +1,4 @@
F is_leap_year(year)
I year % 100 == 0
R year % 400 == 0
R year % 4 == 0

View 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

View 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

View 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.$'

View 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

View 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
)

View 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

View 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.

View file

@ -0,0 +1,3 @@
zLeap year
Z(0=4|year)(0=400|year)~0=100|year

View file

@ -0,0 +1,3 @@
zLeap year
z0.=400 100 4.|year

View file

@ -0,0 +1 @@
Leap0.=400 100 4.|

View file

@ -0,0 +1 @@
Leap0⎕DT,2 29¨

View file

@ -0,0 +1 @@
Leap 1899 1900 1901 1902 1903 1904 1905 1999 2000 2001 2002 2003 2004

View file

@ -0,0 +1 @@
0 0 0 0 0 1 0 0 1 0 0 0 1

View file

@ -0,0 +1,7 @@
function leapyear( year )
{
if ( year % 100 == 0 )
return ( year % 400 == 0 )
else
return ( year % 4 == 0 )
}

View 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

View file

@ -0,0 +1,6 @@
public function isLeapYear(year:int):Boolean {
if (year % 100 == 0) {
return (year % 400 == 0);
}
return (year % 4 == 0);
}

View 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);

View 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)

View 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

View 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))))

View file

@ -0,0 +1,2 @@
(map [leap? _] '(1900 1904 2000 2019 2020 2100))
;; => '( 1904 2000 2020 )

View 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?

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

@ -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)"

View 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

View 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))

View 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

View 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")
$)

View 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

View 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...

View file

@ -0,0 +1,5 @@
define l(y) {
if (y % 100 == 0) y /= 100
if (y % 4 == 0) return(1)
return(0)
}

View 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 ">:#,_$:#@^

View 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")
)
)
& ;

View 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";
}
}

View 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 ");
}
}
}

View 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;
}

View 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

View 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
.

View 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.

View 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

View file

@ -0,0 +1,2 @@
Function IsLeapYear( nYear )
Return Iif( nYear%100 == 0, (nYear%400 == 0), (nYear%4 == 0) )

View file

@ -0,0 +1,2 @@
(defn leap-year? [y]
(and (zero? (mod y 4)) (or (pos? (mod y 100)) (zero? (mod y 400)))))

View file

@ -0,0 +1 @@
10 DEF FNLY(Y)=(Y/4=INT(Y/4))*((Y/100<>INT(Y/100))+(Y/400=INT(Y/400)))

View 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))))

View 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.

View file

@ -0,0 +1,3 @@
p Time.leap_year?(2020)
p Time.leap_year?(2021)
p Time.leap_year?(2022)

View 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));
}

View 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);
}

View 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);

View 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
}
}

View 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

View 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.

View 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

View file

@ -0,0 +1,9 @@
func isLeap(y) {
if y % 100 == 0 {
y % 400 == 0
} else {
y % 4 == 0
}
}
print(isLeap(1984))

View 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

View file

@ -0,0 +1,2 @@
isLeap y | y % 100 == 0 = y % 400 == 0
| else = y % 4 == 0

View 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

View 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))))

View file

@ -0,0 +1,4 @@
-module(gregorian).
-export([leap/1]).
leap( Year ) -> calendar:is_leap_year( Year ).

View 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

View file

@ -0,0 +1 @@
=IF(OR(NOT(MOD(A1,400)),AND(NOT(MOD(A1,4)),MOD(A1,100))),"Leap Year","Not a Leap Year")

View file

@ -0,0 +1,10 @@
ISLEAPYEAR
=LAMBDA(y,
OR(
0 = MOD(y, 400),
AND(
0 = MOD(y, 4),
0 <> MOD(y, 100)
)
)
)

View file

@ -0,0 +1,5 @@
let isLeapYear = System.DateTime.IsLeapYear
assert isLeapYear 1996
assert isLeapYear 2000
assert not (isLeapYear 2001)
assert not (isLeapYear 1900)

View file

@ -0,0 +1,2 @@
USING: calendar prettyprint ;
2011 leap-year? .

View 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.

View 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= ;

View file

@ -0,0 +1 @@
: leap-year? dup 4 mod 0= over 16 mod 0= rot 25 mod 0= not or and ;

View 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

View 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

View 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

View 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;

View 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

View 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

View 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

View 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)

View file

@ -0,0 +1,3 @@
func isLeap(year int) bool {
return year%400 == 0 || year%4 == 0 && year%100 != 0
}

View file

@ -0,0 +1 @@
(1900..2012).findAll {new GregorianCalendar().isLeapYear(it)}.each {println it}

View file

@ -0,0 +1,2 @@
FUNCTION IsLeapYear( nYear )
RETURN iif( nYear % 100 == 0, nYear % 400 == 0, nYear % 4 == 0 )

View 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

View file

@ -0,0 +1 @@
isleap = foldl1 ((&&).not).flip map [400, 100, 4]. ((0==).).mod

View 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

View 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]

View file

@ -0,0 +1,6 @@
(defn leap? [y]
(and
(= (% y 4) 0)
(or
(!= (% y 100) 0)
(= (% y 400) 0))))

View 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

View 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

View file

@ -0,0 +1 @@
isLeap=: 0 -/@:= 4 100 400 |/ ]

View file

@ -0,0 +1,2 @@
isLeap 1900 1996 1997 2000
0 1 0 1

View 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);
}
}

View file

@ -0,0 +1,8 @@
import java.time.Year;
public class IsLeap {
public static void main(String[] args) {
System.out.println(Year.isLeap(2004));
}
}

View file

@ -0,0 +1 @@
var isLeapYear = function (year) { return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0); };

View 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; };

View file

@ -0,0 +1 @@
DEFINE leapyear == dup 100 div null rotate choice 4 rem null.

View file

@ -0,0 +1,2 @@
def leap:
. as $y | ($y%4) == 0 and ($y < 1582 or ($y%400) == 0 or ($y%100) != 0);

View 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))

View 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])

View 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