Last active
December 21, 2015 22:59
-
-
Save AlexVPopov/6378968 to your computer and use it in GitHub Desktop.
Project Euler 4
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
def palindrome?(a) | |
a.to_s == a.to_s.reverse | |
end | |
def dev_by_3digit?(a) | |
999.downto(100) do |i| | |
if a % i == 0 && a / i < 999 | |
return true | |
end | |
end | |
false | |
end | |
largest = 999 * 999 | |
while true do | |
if palindrome?(largest) | |
if dev_by_3digit?(largest) | |
break | |
end | |
end | |
largest -= 1 | |
end | |
puts largest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment