Skip to content

Instantly share code, notes, and snippets.

@mldoscar
Created October 6, 2016 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mldoscar/70c00dc7f078bf3ec7c5ccf641800c00 to your computer and use it in GitHub Desktop.
Save mldoscar/70c00dc7f078bf3ec7c5ccf641800c00 to your computer and use it in GitHub Desktop.
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