Doomsday rule: Difference between revisions

Content added Content deleted
No edit summary
(Added uBasic/4tH version)
Line 1,525: Line 1,525:
</pre>
</pre>


=={{header|uBasic/4tH}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="uBasic/4tH">Dim @f(24)
Push 3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5 ' the first doomsday in each
Push 4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5 ' month for common and leap years
For x = 23 to 0 Step -1 : @f(x) = Pop() : Next
Dim @d(7)
Push Dup("Sunday"), Dup("Monday"), Dup("Tuesday"), Dup("Wednesday")
Push Dup("Thursday"), Dup("Friday"), Dup("Saturday")
For x = 6 To 0 Step -1 : @d(x) = Pop() : Next

Print Show(FUNC(_get_day(1800, 01, 06)))
Print Show(FUNC(_get_day(1875, 03, 29)))
Print Show(FUNC(_get_day(1915, 12, 07)))
Print Show(FUNC(_get_day(1970, 12, 23)))
Print Show(FUNC(_get_day(2043, 05, 14)))
Print Show(FUNC(_get_day(2077, 02, 12)))
Print Show(FUNC(_get_day(2101, 04, 02)))

End

_doomsday ' John Conway's doomsday formula
Param (1) : Return ((2 + 5*(a@ % 4) + 4*(a@ % 100) + 6*(a@ % 400)) % 7)
_leap ' is it a leap year?
Param (1)
If (a@ % 4 > 0) Then Return (0) ' return 0 for common years
If (a@ % 100 = 0) * (a@ % 400 > 0) Then Return (0)
Return (1) ' 1 for leap years

_get_day
Param (3)
Local (2)

d@ = FUNC(_doomsday(a@))
e@ = (7 + c@ - @f(FUNC(_leap(a@)) * 2 + (b@-1))) % 7
Return (@d((d@+e@) % 7))</syntaxhighlight>
{{Out}}
<pre>Monday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

0 OK, 0:711</pre>
=={{header|V (Vlang)}}==
=={{header|V (Vlang)}}==
{{trans|Go}}
{{trans|Go}}