Day of the week: Difference between revisions

→‎{{header|J}}: Icon and Unicon
(adding Mumps example to Day of the Week task)
(→‎{{header|J}}: Icon and Unicon)
Line 617:
2072 2078 2089 2095 2101 2107 2112 2118 ... 999994
</pre>
 
== {{header|Icon}} and {{header|Unicon}} ==
 
<lang Icon>link datetime
 
procedure main()
writes("December 25th is a Sunday in: ")
every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ")
end</lang>
 
 
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime provides dayoweek]
 
<lang Icon>procedure dayoweek(day, month, year) #: day of the week
static d_code, c_code, m_code, ml_code, y, C, M, Y
 
initial {
d_code := ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
 
c_code := table()
c_code[16] := c_code[20] := 0
c_code[17] := c_code[21] := 6
c_code[18] := c_code[22] := 4
c_code[19] := c_code[23] := 2
 
m_code := table()
m_code[1] := m_code["January"] := 1
m_code[2] := m_code["February"] := 4
m_code[3] := m_code["March"] := 4
m_code[4] := m_code["April"] := 0
m_code[5] := m_code["May"] := 2
m_code[6] := m_code["June"] := 5
m_code[7] := m_code["July"] := 0
m_code[8] := m_code["August"] := 3
m_code[9] := m_code["September"] := 6
m_code[10] := m_code["October"] := 1
m_code[11] := m_code["November"] := 4
m_code[12] := m_code["December"] := 6
 
ml_code := copy(m_code)
ml_code[1] := ml_code["January"] := 0
ml_code[2] := ml_code["February"] := 3
}
 
if year < 1600 then stop("*** can't compute day of week that far back")
if year > 2299 then stop("*** can't compute day of week that far ahead")
 
C := c_code[(year / 100) + 1]
y := year % 100
Y := (y / 12) + (y % 12) + ((y % 12) / 4)
month := integer(month)
M := if (year % 4) = 0 then ml_code[month] else m_code[month]
 
return d_code[(C + Y + M + day) % 7 + 1]
end</lang>
 
Sample Output:
<pre>December 25th is a Sunday in: 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|J}}==
Anonymous user