Day of the week: Difference between revisions

→‎{{header|Logo}}: Add implementation.
(→‎{{header|Logo}}: Add implementation.)
Line 1,169:
print count; " years when Christmas Day falls on a Sunday"
end</lang>
 
=={{header|Logo}}==
<lang Logo>; Determine if a Gregorian calendar year is leap
to leap? :year
output (and
equal? 0 modulo :year 4
not member? modulo :year 400 [100 200 300]
)
end
 
; Convert Gregorian calendar date to a simple day count from
; day 1 = January 1, 1 CE
to day_number :year :month :day
local "elapsed make "elapsed difference :year 1
output (sum product 365 :elapsed
int quotient :elapsed 4
minus int quotient :elapsed 100
int quotient :elapsed 400
int quotient difference product 367 :month 362 12
ifelse lessequal? :month 2 0 ifelse leap? :year -1 -2
:day)
end
 
; Find the day of the week from a day number; 0 = Sunday through 6 = Saturday
to day_of_week :day_number
output modulo :day_number 7
end
 
; True if the given day is a Sunday
to sunday? :year :month :day
output equal? 0 day_of_week day_number :year :month :day
end
 
; Generate a list of integers from start through end, inclusive
to seq :start :end
local "start_1 make "start_1 difference :start 1
output cascade difference :end :start_1 [lput sum :start_1 # ?] []
end
 
; Put it all together to answer the question posed in the problem
print filter [sunday? ? 12 25] seq 2008 2121
bye</lang>
 
{{Out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|Lua}}==
1,481

edits