Last active
July 20, 2016 18:51
-
-
Save munyari/b3def2ea9d26fd4886382bb5188b84fe 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
function is_palindrome(n) | |
str = tostring(n) | |
return str == string.reverse(str) | |
end | |
for p = 1, 9 do | |
n = 9 * p + 1 | |
for j = 1, n do | |
if n % j == 0 then | |
a = 1001 - n // j | |
b = 1001 - 11 * j | |
test = a * b | |
if is_palindrome(test) then | |
print(tostring(test)) | |
end | |
end | |
end | |
end |
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? n | |
n.to_s == n.to_s.reverse | |
end | |
for p in 1...9 | |
n = 9 * p + 1 | |
for j in 1...n | |
if n % j == 0 | |
a = 1001 - n / j | |
b = 1001 - 11 * j | |
test = a * b | |
if palindrome?(test) | |
puts "#{test}\n" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment