Created
January 31, 2015 18:20
-
-
Save itsbth/97a3ae700a685b144a5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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.") |
This file contains hidden or 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
| 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