Created
October 6, 2016 19:52
-
-
Save mldoscar/70c00dc7f078bf3ec7c5ccf641800c00 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'date' | |
def days_in_month(year, month) | |
Date.new(year, month, -1).day | |
end | |
range = 2000..2100 | |
found = 0 | |
print "======= SPECIAL NUMBERS SEARCH BEGIN ======\n" | |
print "From years: #{range}\n" | |
for i in range | |
year = i.to_s | |
for j in 1..12 | |
max_day = days_in_month(i,j) | |
for k in 1..max_day | |
whole_string = "#{k}#{j}#{i}" | |
if (whole_string == whole_string.reverse) | |
print "Special number found in: #{k}/#{j}/#{i}: #{whole_string} = #{whole_string.reverse}\n" | |
found += 1 | |
end | |
end | |
end | |
end | |
print "\n" | |
print "Total special numbers found: #{found}\n" | |
print "Credits: nicacode.com\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment