In this simple yet interesting math problem, the answer seems to always fall to the 4, 2, 1 loop. It works like this. If the number is even, it is divided by two. If the number is odd then you multiply it by 3 and add 1. This problem can make interesting patterns and is really cool to see the numbers trickle down to 4, 2, 1.
Yeah, we could do this in our heads, but for larger numbers that may take some time. That’s why we have computers to do the job!
x = Whatever number you want to start off with -- Ex: 10, 5, 1003
while x > 1 do
if x%2 == 0 then -- If number is even or odd
x = x / 2 -- Number is even so divide by two
else
x = x * 3 + 1 -- Number is odd so multiply by three and add one
end
print(x) -- Print the number in the output
end
If you just run this code you’ll get a series of numbers that end in 4, 2, 1. If you don’t end up in 4, 2, 1, let me know because you may have solved this math problem.
You can try it for yourself on this website while Roblox is down.
Mathematical chaos is gorgeous. Unimaginable designs coming from simple, iterated transformations. Almost akin to the birth of a universe: at some point in the visualization of the process, a fulcrum appears at which the data can no longer be contained by patterns, and it seems to become what he describes as “organic” – it breathes and stands on its own feet. It creates itself henceforth, almost as if it had a will, free of the pattern that gave it its wings. The engineer in me thinks pure math is hogwash and fairly useless to think about, but the artist in me can’t help but deeply admire and respect the language our world is written in.