Doomsday rule: Difference between revisions

(→‎{{header|UNIX Shell}}: fix a variable name)
Line 1,579:
<syntaxhighlight lang=bash>#!/usr/bin/env bash
 
day-of-the-week()
conway()
if [[ "$1" =~ ([0-9]{4})-([0-9]{2})-([0-9]{2}) ]]
then
local -ra downames=({Sun,Mon,Tues,Wednes,Thurs,Fri,Satur}day) doomsday=({37,41}7426415375)
local -i i isLeap c s t a b
local -i {year,month,day}=${BASH_REMATCH[++i]}
echo ${downames[
isLeap=(year % 4 == 0) && ( (year % 100) || (year % 400 == 0) ),
c=year/100,
s=(year%100)/12,
Line 1,592 ⟶ 1,591:
a=(5*(c%4)+2) % 7,
b=(s + t + (t / 4) + a ) % 7,
(b + day - ${doomsday[isLeap(year%4 == 0) && ((year%100) || (year%400 == 0))]:month-1:1} + 7) % 7
]}
else return 1
Line 1,598 ⟶ 1,597:
 
for date in 1800-01-06 1875-03-29 1915-12-07 1970-12-23 2043-05-14 2077-02-12 2101-04-02
do conwayday-of-the-week "$date"
done</syntaxhighlight>
 
1,934

edits