Created
March 5, 2010 15:09
-
-
Save cdmoyer/322789 to your computer and use it in GitHub Desktop.
xkcd (http://xkcd.com/710/) inspired Colltaz Conjecture exploration (http://en.wikipedia.org/wiki/Collatz_conjecture)
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
-- Lack of easy access to anything better than second resolution. Blah. | |
math.randomseed(os.time()) | |
-- Successive seeds of os.time() that are close end up creating the same | |
-- value on OSX due to the integer making or random(x,y) losing precision | |
math.randomseed(os.time() * math.random()) | |
local num = math.random(1e7,1e8) | |
while num ~= 1 do | |
str = "" .. num | |
if num % 2 == 0 then | |
num = num / 2 | |
str = str .. " / 2" | |
else | |
num = (num * 3) + 1 | |
str = str .. " * 3 + 1" | |
end | |
print(str) | |
end | |
print(num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment