Skip to content

Instantly share code, notes, and snippets.

@Andrewglass1
Last active December 23, 2015 13:19
Show Gist options
  • Save Andrewglass1/6641271 to your computer and use it in GitHub Desktop.
Save Andrewglass1/6641271 to your computer and use it in GitHub Desktop.
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