Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
52
Task/Doomsday-rule/JavaScript/doomsday-rule.js
Normal file
52
Task/Doomsday-rule/JavaScript/doomsday-rule.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// doom.js
|
||||
const LEAP_DOOM = [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5];
|
||||
const NORM_DOOM = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5];
|
||||
const WEEKDAYS = [
|
||||
'Sunday', 'Monday', 'Tuesday', 'Wednesday',
|
||||
'Thursday', 'Friday', 'Saturday'
|
||||
];
|
||||
|
||||
class Date {
|
||||
constructor(year, month, day) {
|
||||
this.year = year;
|
||||
this.month = month; // 1-based
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
isLeapYear() {
|
||||
const y = this.year;
|
||||
return y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
|
||||
}
|
||||
|
||||
format() {
|
||||
const { month, day, year } = this;
|
||||
return `${String(month).padStart(2, '0')}/${String(day).padStart(2, '0')}/${year}`;
|
||||
}
|
||||
|
||||
weekday() {
|
||||
const { year, month, day } = this;
|
||||
const c = Math.floor(year / 100);
|
||||
const r = year % 100;
|
||||
const s = Math.floor(r / 12);
|
||||
const t = r % 12;
|
||||
|
||||
const cAnchor = (5 * (c % 4) + 2) % 7;
|
||||
const doom = (s + t + Math.floor(t / 4) + cAnchor) % 7;
|
||||
const anchor = (this.isLeapYear() ? LEAP_DOOM : NORM_DOOM)[month - 1];
|
||||
|
||||
return WEEKDAYS[(doom + day - anchor + 7) % 7];
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- demo ---------- */
|
||||
const dates = [
|
||||
new Date(1800, 1, 6),
|
||||
new Date(1875, 3, 29),
|
||||
new Date(1915, 12, 7),
|
||||
new Date(1970, 12, 23),
|
||||
new Date(2043, 5, 14),
|
||||
new Date(2077, 2, 12),
|
||||
new Date(2101, 4, 2)
|
||||
];
|
||||
|
||||
dates.forEach(d => console.log(`${d.format()}: ${d.weekday()}`));
|
||||
15
Task/Doomsday-rule/Maxima/doomsday-rule.maxima
Normal file
15
Task/Doomsday-rule/Maxima/doomsday-rule.maxima
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
daynames: ["Sunday", "Monday", "Tuesday",
|
||||
"Wednesday", "Thursday", "Friday", "Saturday"]$
|
||||
|
||||
isleapyear(y) := mod(y, 4)=0 and (mod(y, 100)#0 or mod(y, 400)=0)$
|
||||
anchors(y) := [if isleapyear(y) then 4 else 3,
|
||||
if isleapyear(y) then 1 else 7,
|
||||
7, 4, 2, 6, 4, 1, 5, 3, 7, 5]$
|
||||
|
||||
doomsday(y) := mod(2+5*mod(y, 4)+4*mod(y, 100)+6*mod(y, 400), 7)$
|
||||
wd(y, m, d) := mod(doomsday(y)+d-anchors(y)[m], 7)$
|
||||
|
||||
test_dates: [[1800, 1, 6], [1875, 3, 29], [1915, 12, 7], [1970, 12, 23], [2043, 5, 14], [2077, 2, 12], [2101, 4, 2]]$
|
||||
|
||||
raw_wds: map(lambda([l], apply(wd, l)), test_dates)$
|
||||
for i in raw_wds do(sprint(daynames[i+1]))$
|
||||
42
Task/Doomsday-rule/Pluto/doomsday-rule.pluto
Normal file
42
Task/Doomsday-rule/Pluto/doomsday-rule.pluto
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
local fmt = require "fmt"
|
||||
|
||||
local anchor_day = |y| -> (2 + 5 * (y % 4) + 4 *(y % 100) + 6 * (y % 400)) % 7
|
||||
|
||||
local is_leap_year = |y| -> y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)
|
||||
|
||||
local first_days_common = {3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5}
|
||||
local first_days_leap = {4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5}
|
||||
|
||||
local dates = {
|
||||
"1800-01-06",
|
||||
"1875-03-29",
|
||||
"1915-12-07",
|
||||
"1970-12-23",
|
||||
"2043-05-14",
|
||||
"2077-02-12",
|
||||
"2101-04-02"
|
||||
}
|
||||
|
||||
local function parse(date)
|
||||
local y = tonumber(date:sub(1, 4))
|
||||
local m = tonumber(date:sub(6, 7))
|
||||
local d = tonumber(date:sub(9, 10))
|
||||
return y, m, d
|
||||
end
|
||||
|
||||
print("Days of week given by Doomsday rule:")
|
||||
for dates as date do
|
||||
local y, m, d = parse(date)
|
||||
local a = anchor_day(y)
|
||||
local w = d - (is_leap_year(y) ? first_days_leap[m] : first_days_common[m])
|
||||
if w < 0 then w += 7 end
|
||||
local dow = (a + w) % 7
|
||||
print($"{date} -> {fmt.weekday(dow)}")
|
||||
end
|
||||
|
||||
print("\nDays of week given by standard library functions:")
|
||||
for dates as date do
|
||||
local y, m, d = parse(date)
|
||||
local t = os.time({year = y, month = m, day = d})
|
||||
print($"{date} -> {os.date("%A", t)}")
|
||||
end
|
||||
22
Task/Doomsday-rule/R/doomsday-rule.r
Normal file
22
Task/Doomsday-rule/R/doomsday-rule.r
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
daynames <- c("Sunday", "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday")
|
||||
|
||||
isleapyear <- function(y) (y%%4==0)&((y%%100!=0)|(y%%400==0))
|
||||
|
||||
anchors <- function(y) c(ifelse(isleapyear(y), 4, 3),
|
||||
ifelse(isleapyear(y), 1, 7),
|
||||
7, 4, 2, 6, 4, 1, 5, 3, 7, 5)
|
||||
|
||||
doomsday <- function(y) (2+5*(y%%4)+4*(y%%100)+6*(y%%400))%%7
|
||||
wd <- function(y, m, d) (doomsday(y)+d-anchors(y)[m])%%7
|
||||
|
||||
test_dates <- list(c(1800, 1, 6),
|
||||
c(1875, 3, 29),
|
||||
c(1915, 12, 7),
|
||||
c(1970, 12, 23),
|
||||
c(2043, 5, 14),
|
||||
c(2077, 2, 12),
|
||||
c(2101, 4, 2))
|
||||
|
||||
raw_wds <- sapply(test_dates, function(v) do.call(wd, as.list(v)))
|
||||
cat(daynames[raw_wds+1], "\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue