Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Last active January 2, 2016 09:39
Show Gist options
  • Select an option

  • Save ytkhs/8284307 to your computer and use it in GitHub Desktop.

Select an option

Save ytkhs/8284307 to your computer and use it in GitHub Desktop.
8桁の数字で素数となる日付
require 'prime'
require 'date'
def primedays(year)
Array(Date.new(year,1,1)..Date.new(year,12,31)).flat_map {|d|
Prime.prime?(d.strftime('%Y%m%d').to_i) ? [d.to_s] : []
}
end
primedays(2014)
# => ["2014-02-01","2014-02-13","2014-03-01","2014-03-03","2014-03-27","2014-03-31","2014-04-11","2014-04-23","2014-04-29","2014-06-09","2014-06-13","2014-06-19","2014-08-07","2014-08-23","2014-08-29","2014-08-31","2014-09-07","2014-09-09","2014-09-27","2014-10-03","2014-10-21","2014-11-01","2014-11-11","2014-12-01","2014-12-03","2014-12-07","2014-12-21"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment