Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,50 @@
type Date = struct {
word year;
byte month;
byte day;
};
proc leap_year(word y) bool:
y%4 = 0 and (y%100 /= 0 or y % 400 = 0)
corp
proc weekday(Date date) *char:
[12]byte leapdoom = (4,1,7,4,2,6,4,1,5,3,7,5);
[12]byte normdoom = (3,7,7,4,2,6,4,1,5,3,7,5);
word c, r, s, t, c_anchor, doom, anchor;
c := date.year / 100;
r := date.year % 100;
s := r / 12;
t := r % 12;
c_anchor := (5 * (c % 4) + 2) % 7;
doom := (s + t + (t/4) + c_anchor) % 7;
anchor := if leap_year(date.year)
then leapdoom[date.month-1]
else normdoom[date.month-1]
fi;
case (doom+date.day-anchor+7)%7
incase 0: "Sunday"
incase 1: "Monday"
incase 2: "Tuesday"
incase 3: "Wednesday"
incase 4: "Thursday"
incase 5: "Friday"
incase 6: "Saturday"
esac
corp
proc main() void:
[7]Date dates = (
(1800,1,6), (1875,3,29), (1915,12,7), (1970,12,23), (2043,5,14),
(2077,2,12), (2101,4,2)
);
word d;
for d from 0 upto 6 do
writeln(dates[d].month:2, '/', dates[d].day:2, '/', dates[d].year:4,
": ", weekday(dates[d]))
od
corp

View file

@ -0,0 +1,60 @@
' MAKE USING("FORMAT STRING", PAR1, PAR2, ...PARN)
' WE USE READ V TO READ MORE PARAMETERS.
FUNCTION USING(A$) {
VARIANT V : LONG D, S, E, I=1: S$=""
WHILE I<=LEN(A$)
IF S THEN
IF MID$(A$,I,1)<>"#" THEN
IF MID$(A$,I,1)="." THEN D=I ELSE E=I
END IF
ELSE
IF MID$(A$,I,1)="#" THEN S=I
END IF
IF S AND E THEN
IF S>1 THEN S$+=LEFT$(A$, S-1)
A$=MID$(A$, E)
G()
S=0:E=0:D=0
I=1
END IF
I++
END WHILE
IF S THEN
IF S>1 THEN S$+=LEFT$(A$, S-1):E=I-S+1: S=1 ELSE E=I
G()
=S$
ELSE
=S$+A$
END IF
SUB G()
IF ISNUM THEN
READ V
IF D>0 THEN
S$+=STR$(V, STRING$("#",E-D-1)+"0."+STRING$("0",D-S+1))
ELSE
S$+=STR$(V, STRING$("0",E-S-1)+"0")
END IF
ELSE
V=""
READ V
S$+=LEFT$(V+STRING$(" ", E-S), E-S)
END IF
END SUB
}
05 FLUSH : GOSUB 110
10 DIM D$(1 TO 7): FOR I=1 TO 7: READ D$(I): NEXT I
20 DIM D(1 TO 12, 0 TO 1): FOR I=0 TO 1: FOR J=1 TO 12: READ D(J, I): NEXT J : NEXT I
30 READ Y: IF Y=0 THEN BREAK ELSE READ M,D
40 PRINT USING("##/##/#### ", M, D, Y);
50 C=Y DIV 100: R=Y MOD 100
60 S=R DIV 12: T=R MOD 12
70 A=(5*BINARY.AND(C, 3)+2) MOD 7
80 B=(S+T+(T DIV 4)+A) MOD 7
90 PRINT D$((B+D-D(M,-(Y MOD 4=0 AND (Y MOD 100<>0 OR Y MOD 400=0)))+7) MOD 7+1)
100 GOTO 30
110 DATA "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
120 DATA 3,7,7,4,2,6,4,1,5,3,7,5
130 DATA 4,1,7,4,2,6,4,1,5,3,7,5
140 DATA 1800,1,6,1875,3,29,1915,12,7,1970,12,23
150 DATA 2043,5,14,2077,2,12,2101,4,2,0
160 RETURN

View file

@ -0,0 +1,29 @@
main :: [sys_message]
main = [Stdout (lay [showdate d ++ ": " ++ weekday d | d<-tests])]
date ::= Date (num,num,num)
showdate :: date->[char]
showdate (Date (y,m,d)) = show m ++ "/" ++ show d ++ "/" ++ show y
tests :: [date]
tests = map Date [
(1800,1,6), (1875,3,29), (1915,12,7), (1970,12,23), (2043,5,14),
(2077,2,12), (2101,4,2)]
weekday :: date->[char]
weekday (Date (year,month,day))
= weekdays ! daynum
where weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday"]
doomtab = leapdoom, if leapyear
= normdoom, otherwise
leapdoom = [4,1,7,2,4,6,4,1,5,3,7,5]
normdoom = [3,7,7,4,2,6,4,1,5,3,7,5]
leapyear = year mod 4=0 & (year mod 100~=0 \/ year mod 400=0)
(c, r) = (year div 100, year mod 100)
(s, t) = (r div 12, r mod 12)
c_anchor = (5 * (c mod 4) + 2) mod 7
doom = (s + t + t div 4 + c_anchor) mod 7
anchor = doomtab ! (month - 1)
daynum = (doom + day - anchor + 7) mod 7

View file

@ -0,0 +1,26 @@
[ dup 400 mod 0 = iff [ drop true ] done
dup 100 mod 0 = iff [ drop false ] done
4 mod 0 = ] is leap ( y --> b )
[ dup 4 mod 5 *
over 100 mod 4 * +
swap 400 mod 6 * + 2 + 7 mod ] is doomsday ( y --> n )
[ leap iff [ ' [ table 0 4 1 ] ]
else [ ' [ table 0 3 7 ] ]
' [ 7 4 2 6 4 1 5 3 7 5 ] join do ] is close ( m y --> n )
[ dup doomsday unrot close - + 7 mod ] is weekday ( d m y --> n )
[ [ table $ "Sunday" $ "Monday"
$ "Tuesday" $ "Wednesday" $ "Thursday"
$ "Friday" $ "Saturday" ] do echo$ ] is echoday ( d --> )
' [ [ 6 1 1800 ]
[ 29 3 1875 ]
[ 7 12 1915 ]
[ 23 12 1970 ]
[ 14 5 2043 ]
[ 12 2 2077 ]
[ 2 4 2101 ] ]
witheach [ unpack weekday echoday cr ]

View file

@ -0,0 +1,43 @@
$ENTRY Go {
, (1800 1 6) (1875 3 29) (1915 12 7) (1970 12 23)
(2043 5 14) (2077 2 12) (2101 4 2): e.Tests
= <Each (Test) e.Tests>;
};
Test {
e.Test = <Prout e.Test <Weekday e.Test>>;
};
LeapYear {
s.Year = <And <Eq 0 <Mod s.Year 4>>
<Or <Neq 0 <Mod s.Year 100>>
<Eq 0 <Mod s.Year 400>>>>;
};
Weekday {
s.Year s.Month s.Day,
4 1 7 4 2 6 4 1 5 3 7 5: e.LeapDoom,
3 7 7 4 2 6 4 1 5 3 7 5: e.NormDoom,
Sunday Monday Tuesday Wednesday Thursday Friday Saturday: e.Days,
<Divmod s.Year 100>: (s.C) s.R,
<Divmod s.R 12>: (s.S) s.T,
<Mod <Add 2 <Mul 5 <Mod s.C 4>>> 7>: s.CAn,
<Mod <Add s.S <Add s.T <Add s.CAn <Div s.T 4>>>> 7>: s.Doom,
<If <LeapYear s.Year> (e.LeapDoom) (e.NormDoom)>: (e.DoomTab),
<Item <Sub s.Month 1> e.DoomTab>: e.Anchor,
<Mod <Add 7 <Sub <Add s.Doom s.Day> e.Anchor>> 7>: s.Weekday
= <Item s.Weekday e.Days>;
};
Item {
0 s.X e.XS = s.X;
s.N s.X e.XS = <Item <Sub s.N 1> e.XS>;
};
If { True t.T t.F = t.T; False t.T t.F = t.F; };
Eq { t.X t.X = True; t.X t.Y = False; };
Or { True s.Y = True; False s.Y = s.Y; };
And { False s.Y = False; True s.Y = s.Y; };
Not { True = False; False = True; };
Neq { t.X t.Y = <Not <Eq t.X t.Y>>; };
Each { (e.F) = ; (e.F) (e.X) e.XS = <Mu e.F e.X> <Each (e.F) e.XS>; };

View file

@ -0,0 +1,29 @@
program doomsday;
tests := [[1800,1,6], [1875,3,29], [1915,12,7], [1970,12,23],
[2043,5,14], [2077,2,12], [2101,4,2]];
loop for [year, month, day] in tests do
print(str day + "/" + str month + "/" + str year + ": " +
weekday(year, month, day));
end loop;
proc leap(y);
return y mod 4 = 0 and (y mod 100 /= 0 or y mod 400 = 0);
end proc;
proc weekday(year, month, day);
leapdoom := [4,1,7,4,2,6,4,1,5,3,7,5];
normdoom := [3,7,7,4,2,6,4,1,5,3,7,5];
weekdays := ["Sunday","Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday"];
c := year div 100;
r := year mod 100;
s := r div 12;
t := r mod 12;
c_anchor := (5 * (c mod 4) + 2) mod 7;
doom := (s + t + (t div 4) + c_anchor) mod 7;
anchor := if leap(year) then leapdoom else normdoom end(month);
return weekdays((doom+day-anchor+7) mod 7+1);
end proc;
end program;

View file

@ -5,14 +5,14 @@ day-of-the-week()
then
local -ra names=({Sun,Mon,Tues,Wednes,Thurs,Fri,Satur}day) doomsday=({37,41}7426415375)
local -i i c s t a b
local -i {year,month,day}=${BASH_REMATCH[++i]}
local -i {y,m,d}=${BASH_REMATCH[++i]}
echo ${names[
c=year/100,
s=(year%100)/12,
t=(year % 100) % 12,
c=y/100,
s=(y%100)/12,
t=(y % 100) % 12,
a=(5*(c%4)+2) % 7,
b=(s + t + (t / 4) + a ) % 7,
(b + day - ${doomsday[(year%4 == 0) && ((year%100) || (year%400 == 0))]:month-1:1} + 7) % 7
(b + d - ${doomsday[(y%4 == 0) && ((y%100) || (y%400 == 0))]:m-1:1} + 7) % 7
]}
else return 1
fi

View file

@ -1,5 +1,4 @@
const
(
const (
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
first_days_common = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
first_days_leap = [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
@ -24,15 +23,11 @@ fn main() {
d = date[8..10].int()
a = anchor_day(y)
f = first_days_common[m]
if is_leap_year(y) {
f = first_days_leap[m]
}
if is_leap_year(y) {f = first_days_leap[m]}
w = d - f
if w < 0 {
w = 7 + w
}
if w < 0 {w = 7 + w}
dow = (a + w) % 7
println('$date -> ${days[dow]}')
println("$date -> ${days[dow]}")
}
}