1234567891011121314151617181920212223242526272829303132333435 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
- # https://projecteuler.net/problem=19
- # Runtime: 0.446s
- require('DateTime')
- func first_sundays(year) {
- var count = 0
- for i in (1..12) {
- var date = %O<DateTime>.new(
- year => year,
- month => i,
- day => 1,
- )
- ++count if (date.dow == 7)
- }
- return count
- }
- var total = 0
- for year in (1901 .. 2000) {
- total += first_sundays(year)
- }
- say total
|