Okay, so I saw a new veritasium video: The Simplest Math Problem No One Can Solve - Collatz Conjecture - YouTube about the Collatz Conjecture.
Essentially: get a number.
2 rules:
If the number is odd: Multiply it by 3 and add 1.
If the number is even: Divide by 2.
It’s theorized, that it will always get to the number 1, and since one is odd, multiply it by 3, and add 1. You have 4. Then divide by 2, which is 2, it’s even, so divide by 2 again, you get one. Infinite loop.
I decided I wanted to visualize this in studio, with screen gui’s, because why not?
But the problem is, I can’t seem to position is properly. The higher the number is. The lower it goes, but I want it to be the opposite, and I can’t seem to get it to position correctly.
Here’s my script. It’s super simple, but idk what to do.
local MainFrame = script.Parent.MainFrame
local Format = MainFrame.Format
local function Even(num)
return (num % 2 == 0)
end
script.Event.Event:Connect(function(numberToStart)
for i,v in pairs(MainFrame:GetChildren()) do
if v.Name ~= "Format" then
v:Destroy()
end
end
local NumbersIterated = 1
local Number = numberToStart
while true do
wait()
if Even(Number) then
Number /= 2
elseif not Even(Number) then
Number = (Number*3)+1
end
print(Number)
local NewFormat = Format:Clone()
NewFormat.Name = tostring(Number)
NewFormat.Text = tostring(Number)
NewFormat.Position = UDim2.new(NumbersIterated/100,0,Number/1000,0)
NewFormat.Visible = true
NewFormat.Parent = MainFrame
if Number == 1 then
print("It reached one.")
break
end
NumbersIterated += 1
end
end)
My goal is to eventually get something like this. I’ll work on the lines later.


