Last active
December 23, 2015 13:19
-
-
Save Andrewglass1/6641271 to your computer and use it in GitHub Desktop.
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
THREE_DIGIT_NUMBERS = (100..999).to_a | |
MAX = 999 * 999 | |
MIN = 100 * 100 | |
def is_palindrome?(input) | |
input.to_s == input.to_s.reverse | |
end | |
def three_digit_factors(input) | |
input = input.to_i | |
(100..999).to_a.each do |i| | |
if input % i == 0 && (input/i).to_s.length == 3 | |
return [input/i, i] | |
end | |
end | |
return false | |
end | |
(MIN..MAX).to_a.reverse.each do |num| | |
if is_palindrome?(num) && three_digit_factors(num) | |
raise "This pair #{three_digit_factors(num)} makes a palindrome" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment