Last active
August 29, 2015 14:25
-
-
Save sts10/a44b0d57e9fdf2f5dca4 to your computer and use it in GitHub Desktop.
Makes array of dates where (day + month + last_two_digits_of_year) and number of days since Jan 1, 1970 have both been prime since Jan 1, 1970
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makes array of dates where (day + month + last_two_digits_of_year) and number of days since Jan 1, 1970 have both been prime since Jan 1, 1970 | |
require 'prime' | |
require 'date' | |
def date_to_sum(date) | |
date.month + date.day + date.year.to_s[2..-1].to_i | |
end | |
date_to_go_up_to = Date.parse("2017-01-01") | |
first_day = Date.parse('1970-01-01') | |
this_day = first_day | |
days_since_jan_1_70 = 0 | |
days_it_happened = [] | |
while this_day <= date_to_go_up_to | |
if Prime.prime?(days_since_jan_1_70) && Prime.prime?(date_to_sum(this_day)) | |
puts "it happened on #{this_day.to_s} because #{days_since_jan_1_70} and #{date_to_sum(this_day)} are both prime numbers." | |
days_it_happened << this_day | |
end | |
this_day = this_day + 1 | |
days_since_jan_1_70 = days_since_jan_1_70 + 1 | |
end | |
puts "Between #{first_day} and #{date_to_go_up_to}, there were #{days_it_happened.size} 'prime days'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment