Skip to content

Instantly share code, notes, and snippets.

@expajp
Last active July 31, 2018 12:56
Show Gist options
  • Save expajp/17c4b6327e5176c4562d3f9ca25b5fb1 to your computer and use it in GitHub Desktop.
Save expajp/17c4b6327e5176c4562d3f9ca25b5fb1 to your computer and use it in GitHub Desktop.
「Project Eulerから生まれたワンライナーたち」(https://goo.gl/Dd5RPq ) の第2問を``require 'date'``なしで解くワンライナーです
[*1..1199].map{ |n|
(
(
[
([31]*12).map.with_index{ |n, i|
[2, 4, 6, 9, 11].include?(i+1) ?
(i+1 == 2 ? 28 : 30) :
n
}
]*100
).map.with_index{ |year, i|
(i+1)%4 == 0 ?
year.map{ |n| n == 28 ? 29 : n } :
year
}.flatten
)[0..n-1].sum
}.map{ |days| days%7 == 5 }.count{ |_| _ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment