User guide
13.4. FRIDAYS 215
LET start() = VALOF
{ all := 1
FOR i = 1 TO 16 DO
{ count := 0
try(0, 0, 0)
writef("Number of solutions to %i2-queens is %i9*n", i, count)
all := 2*all + 1
}
RESULTIS 0
}
13.4 Fridays
The following program prints a table of how often the 13
th
day of the month lies on
each day of the week over a 400 year period. Since there are an e x ac t number of weeks
in 4 ce nturies, program sh ows that the 13
th
is most of a Friday!
GET "libhdr"
MANIFEST { mon=0; sun=6; jan=0; feb=1; dec=11 }
LET start() = VALOF
{ LET count = TABLE 0, 0, 0, 0, 0, 0, 0
LET daysinmonth = TABLE 31, ?, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31
LET days = 0
FOR year = 1973 TO 1973+399 DO
{ daysinmonth!feb := febdays(year)
FOR month = jan TO dec DO
{ LET day13 = (days+12) REM 7
count!day13 := count!day13 + 1
days := days + daysinmonth!month
}
}
FOR day = mon TO sun DO
writef("%i3 %sdays*n",
count!day,
select(day,
"Mon","Tues","Wednes","Thurs","Fri","Sat","Sun")
)
RESULTIS 0
}
AND febdays(year) = year REM 400 = 0 -> 29,
year REM 100 = 0 -> 28,
year REM 4 = 0 -> 29,
28
AND select(n, a0, a1, a2, a3, a4, a5, a6) = n!@a0