This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,26 @@
#lang racket
(require srfi/19)
(define long-months '(1 3 5 7 8 10 12))
(define days #(sun mon tue wed thu fri sat))
(define (week-day date)
(vector-ref days (date-week-day date)))
(define (five-weekends-a-month start end)
(for*/list ([year (in-range start (+ end 1))]
[month long-months]
[date (in-value (make-date 0 0 0 0 31 month year 0))]
#:when (eq? (week-day date) 'sun))
date))
(define weekends (five-weekends-a-month 1900 2100))
(define count (length weekends))
(displayln (~a "There are " count " weeks with five weekends."))
(displayln "The first five are: ")
(for ([w (take weekends 5)])
(displayln (date->string w "~b ~Y")))
(displayln "The last five are: ")
(for ([w (drop weekends (- count 5))])
(displayln (date->string w "~b ~Y")))

View file

@ -0,0 +1,13 @@
There are 201 weeks with five weekends.
The first five are:
Mar 1901
Aug 1902
May 1903
Jan 1904
Jul 1904
The last five are:
Mar 2097
Aug 2098
May 2099
Jan 2100
Oct 2100

View file

@ -9,9 +9,9 @@ dates = (start..stop).find_all do |day|
end
puts "There are #{dates.size} months with 5 weekends from 1900 to 2100:"
puts dates[0, 5].map { |d| d.strftime("%b %Y") }.join("\n")
puts dates.first(5).map { |d| d.strftime("%b %Y") }
puts "..."
puts dates[-5, 5].map { |d| d.strftime("%b %Y") }.join("\n")
puts dates.last(5).map { |d| d.strftime("%b %Y") }
years_with_5w = dates.map(&:year)