Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,35 +0,0 @@
-- 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

@ -1,12 +0,0 @@
; 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

@ -1,29 +0,0 @@
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

@ -1,33 +0,0 @@
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

@ -1,4 +0,0 @@
(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

@ -1,3 +0,0 @@
function isLeapYear(integer year)
return remainder(year,4)=0 and remainder(year,100)!=0 or remainder(year,400)=0
end function

View file

@ -1,4 +1,14 @@
MODULE Dates;
IMPORT Out;
CONST SUNDAY* = 0;
MONDAY* = 1;
TUESDAY* = 2;
WEDNESDAY* = 3;
THURSDAY* = 4;
FRIDAY* = 5;
SATURDAY* = 6;
(* returns TRUE if year is a leap year, FALSE otherwise.
assumes year is in the Gregorian Calendar
@ -9,4 +19,68 @@ PROCEDURE isLeapYear* ( year : INTEGER ) : BOOLEAN ;
OR ( ( year MOD 4 = 0 ) & ( year MOD 100 # 0 ) )
END isLeapYear ;
(* returns the day of the week of 31st December of year *)
PROCEDURE dayOfYearEnd* ( year : INTEGER ) : INTEGER ;
BEGIN
RETURN ( year + ( year DIV 4 ) - ( year DIV 100 ) + ( year DIV 400 ) ) MOD 7
END dayOfYearEnd ;
(* returns TRUE if year is a long year (i.e., has 53 weeks), FaLSE otherwise *)
PROCEDURE isLongYear* ( year : INTEGER ) : BOOLEAN ;
BEGIN
(* year is a long year if 31st December is a Thursday
* or the first of January is a Thursday (and so the previous
* year had 31st December on a Wednesday)
*)
RETURN ( dayOfYearEnd( year ) = THURSDAY )
OR ( dayOfYearEnd( year - 1 ) = WEDNESDAY )
END isLongYear ;
(* returns the day of the week of d/m/y *)
PROCEDURE dayOfWeek* ( d, m, y : INTEGER ) : INTEGER ;
VAR j, k, mm, yy, w1 : INTEGER;
BEGIN
mm := m;
yy := y;
IF mm <= 2 THEN
INC( mm, 12 );
DEC( yy )
END;
j := yy DIV 100;
k := yy MOD 100;
(* w1 is the day of the week, Saturday = 0, Sunday = 1, ... *)
w1 := ( d + ( ( mm + 1 ) * 26 ) DIV 10 + k + k DIV 4 + j DIV 4 + 5 * j ) MOD 7;
(* convert w1 to Sunday = 0, Monday = 1, ... *)
IF w1 = 0 THEN
w1 := SATURDAY
ELSE
w1 := w1 - 1
END
RETURN w1
END dayOfWeek ;
(* Writes the date dd/mm/yyyy to standard output, in yyyy-mm-dd format *)
PROCEDURE OutDate* ( dd, mm, yyyy : INTEGER ) ;
BEGIN
Out.Int( yyyy, 4 );
IF mm < 10 THEN Out.String( "-0" ) ELSE Out.String( "-1" ) END;
Out.Int( mm MOD 10, 1 );
IF dd < 10 THEN Out.String( "-0" ) ELSE Out.String( "-" ) END;
Out.Int( dd, 1 )
END OutDate ;
(* Writes the name of day to standard output *)
PROCEDURE OutDayName* ( day : INTEGER ) ;
BEGIN
IF day = SUNDAY THEN Out.String( "Sunday" )
ELSIF day = MONDAY THEN Out.String( "Monday" )
ELSIF day = TUESDAY THEN Out.String( "Tuesday" )
ELSIF day = WEDNESDAY THEN Out.String( "Wednesday" )
ELSIF day = THURSDAY THEN Out.String( "Thursday" )
ELSIF day = FRIDAY THEN Out.String( "Friday" )
ELSIF day = SATURDAY THEN Out.String( "Saturday" )
ELSE Out.String( "Invaliday" )
END
END OutDayName ;
END Dates.

View file

@ -1,17 +0,0 @@
program LeapYear;
uses
sysutils;//includes isLeapYear
procedure TestYear(y: word);
begin
if IsLeapYear(y) then
writeln(y,' is a leap year')
else
writeln(y,' is NO leap year');
end;
Begin
TestYear(1900);
TestYear(2000);
TestYear(2100);
TestYear(1904);
end.

View file

@ -1,2 +0,0 @@
$Year = 2016
[System.DateTime]::IsLeapYear( $Year )

View file

@ -1,15 +0,0 @@
leap-year?: func [
{Returns true if the specified year is a leap year; false otherwise.}
year [date! integer!]
/local div?
][
either date? year [year: year/year] [
if negative? year [throw make error! join [script invalid-arg] year]
]
; The key numbers are 4, 100, and 400, combined as follows:
; 1) If the year is divisible by 4, its a leap year.
; 2) But, if the year is also divisible by 100, its not a leap year.
; 3) Double but, if the year is also divisible by 400, it is a leap year.
div?: func [n] [zero? year // n]
to logic! any [all [div? 4 not div? 100] div? 400]
]

View file

@ -1,17 +0,0 @@
Function IsLeapYear(yr)
IsLeapYear = False
If yr Mod 4 = 0 And (yr Mod 400 = 0 Or yr Mod 100 <> 0) Then
IsLeapYear = True
End If
End Function
'Testing the function.
arr_yr = Array(1900,1972,1997,2000,2001,2004)
For Each yr In arr_yr
If IsLeapYear(yr) Then
WScript.StdOut.WriteLine yr & " is leap year."
Else
WScript.StdOut.WriteLine yr & " is NOT leap year."
End If
Next