Skip to content

Instantly share code, notes, and snippets.

@itsbth
Created January 31, 2015 18:20
Show Gist options
  • Select an option

  • Save itsbth/97a3ae700a685b144a5d to your computer and use it in GitHub Desktop.

Select an option

Save itsbth/97a3ae700a685b144a5d to your computer and use it in GitHub Desktop.
local largest = -1
local iterations = 0
local is_palindrome
is_palindrome = function(n)
n = tostring(n)
return n == n:reverse()
end
for x = 100, 999 do
for y = 999, x, -1 do
local _continue_0 = false
repeat
iterations = iterations + 1
local prod = x * y
if prod < largest then
break
end
if not is_palindrome(prod) then
_continue_0 = true
break
end
largest = prod
_continue_0 = true
until true
if not _continue_0 then
break
end
end
end
return print("Found answer: " .. tostring(largest) .. " after " .. tostring(iterations) .. " iterations.")
largest = -1
iterations = 0
is_palindrome = (n) ->
n = tostring(n)
n == n\reverse()
for x = 100, 999
for y = 999, x, -1
iterations += 1
prod = x * y
break if prod < largest
continue if not is_palindrome(prod)
largest = prod
print("Found answer: #{largest} after #{iterations} iterations.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment