Skip to content

Instantly share code, notes, and snippets.

@k-hamada
Created April 29, 2012 13:10
Show Gist options
  • Save k-hamada/2550377 to your computer and use it in GitHub Desktop.
Save k-hamada/2550377 to your computer and use it in GitHub Desktop.
今後100年間で、今年と同じカレンダーの年を探す
require 'date'
first = Date.new(2012, 1, 1)
last = Date.new(2012, 12, 31)
this_year = [first.wday, last.wday, last.yday]
Enumerator.new{|y|
loop {
first, last = first.next_year, last.next_year
y << [first, last]
}
}
.take(100)
.find_all{|f, l|
[f.wday, l.wday, l.yday] === this_year
}.each{|f, l|
puts f.year
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment