Skip to content

Instantly share code, notes, and snippets.

@cdmoyer
Created March 5, 2010 15:09
Show Gist options
  • Save cdmoyer/322789 to your computer and use it in GitHub Desktop.
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)
-- 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