Doomsday rule: Difference between revisions

add bash entry
imported>Thebeez
(add bash entry)
Line 1,573:
 
0 OK, 0:711</pre>
 
=={{header|UNIX Shell}}==
{{trans|raku}}
{{works with|Bash}}
<syntaxhighlight lang=bash>#!/usr/bin/env bash
 
conway() {
local -ra dow=({Sun,Mon,Tues,Wednes,Thurs,Fri,Satur}day)
local -ra doomsday=(377426415375 417426415375)
local -i year month day isLeap c s t a b
[[ "$1" =~ ([0-9]{4})-([0-9]{2})-([0-9]{2}) ]] || return 1
year=${BASH_REMATCH[1]}
month=${BASH_REMATCH[2]}
day=${BASH_REMATCH[3]}
 
((
isLeap=(year % 4 == 0) && ( (year % 100) || (year % 400 == 0) ),
c=year/100,
s=(year%100)/12,
t=(year % 100) % 12,
a=(5*(c%4)+2) % 7,
b=(s + t + (t / 4) + a ) % 7
))
 
echo ${dow[(b + day - ${doomsday[is-leap]:month-1:1} + 7) % 7]}
 
}
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 conway "$date"
done</syntaxhighlight>
 
{{out}}
<pre>Monday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
</pre>
 
=={{header|V (Vlang)}}==
1,934

edits