2014-09-14

# Problem 019: Counting Sundays

Description:

You are given the following information, but you may prefer to do some research for yourself.

• 1 Jan 1900 was a Monday.
• Thirty days has September,
• April, June and November.
• All the rest have thirty-one,
• Saving February alone,
• Which has twenty-eight, rain or shine.
• And on leap years, twenty-nine.
• A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

Solution:
v303232332323
v313232332323
6
>2*>::0g"0"-47*+\0p::v
|:-1p1\+*74-"0"g1 <
v \$<
>202p112p122p"2&"*1+32p092pv
v20+1g20p29+g29!+-1g21%7g20<>#       0# v#   <      >                 >v
>p12g1+12p32g4%             |       >1 >>22g\g12g1--|
>32g"d"%|  0^ <  #      >112p22g:1+22p66+-|
v%*4"d"g23<>#^_1^  |-+1*"(2"g23<p23+1g23p221<
>          ^>1^    >92g.@      ^             <
Start
??
Pause
Reset
Output:
Stack:   (0)

Explanation:

In the first two rows we remember the day-count of each month. First row is normal years, second row leap years. Then we just enumerate through all days and test if its a Sunday and the first of month.

 Interpreter steps: 3 197 878 Execution time (BefunExec): 546ms (5.86 MHz) Program size: 72 x 12 (fully conform befunge-93) Solution: 171 Solved at: 2014-09-14

made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript