Skip to content

Instantly share code, notes, and snippets.

@munyari
Last active July 20, 2016 18:51
Show Gist options
  • Save munyari/b3def2ea9d26fd4886382bb5188b84fe to your computer and use it in GitHub Desktop.
Save munyari/b3def2ea9d26fd4886382bb5188b84fe to your computer and use it in GitHub Desktop.
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
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