Collatz Conjecture Replicated in Snap!

I was watching a video about the Collatz Conjecture on YouTube: The Simplest Math Problem No One Can Solve - Collatz Conjecture - YouTube

I found it pretty interesting and wanted to replicate it into Snap!. I would have done this in Python or some other language in REPL but Python in REPL has surprisingly smaller number limits than Snap! :frowning: and if I go higher, REPL displays a message in the console that the "signal was killed" or something. Anyways. Here's the link (hopefully, I'll be adding a graph to show each number's pattern soon.): Collatz Conjecture

The way this algorithm works (if you're too lazy to watch the video which I get.), is that you have a random number. Say you pick 10. If this number is even, which it is, then you divide by 2. Else, you multiply by 3, then add 1. So in this case, it would go like this: 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, 4, 2,1. As you can see, this 4, 2, 1 loop continues on and on and on.

Another example. let's say we start with 2541. Here is how it would go.2541, 7624, 3812, 1906, 953, 2860, 1430, 715, 2146, 1073, 3220, 1610, 805, 2416, 1208, 604, 302, 151, 454, 227, 682, 341, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1. Yet again, we're in this 4, 2, 1 loop.

The unsolved part is: does this 4, 2, 1 loop apply to every number all the way up to infinity? The most anyone's ever gone to is 2^68. Around 300 quintillion.

I thought it'd be fun to see the highest number we've checked that applies to the Collatz Conjecture in Snap! so far (even though we're probably not going to hit 300 quintillion):

Nice project. I have two suggestions:

  1. Record how many steps it takes to get to 1.

  2. Instead of making each entry in NUM INFO be a dictionary, just make it a list of two (or three if you take suggestion 1) numbers, because as it is the watcher just shows that each cell is a list, and you have to click on all the cells to see what it's trying to tell you. You can have the first line of NUM INFO be (list (num) (high) (steps)) (those are text strings, not variable blobs!) as a header.

PS it's funny that for all the multi-word variables other than NUM INFO you use underline characters instead of spaces... Bad habit from some text language, I'm guessing. :~)

  1. Yes I'll be adding that on top of a graph that shows the highs and lows of N.
  2. Oh yeah. Because the index number is the num. Huh. Didn't quite think of that.

Ah. Yes, I forgot to put the underline there. Yes, I have to use underlines or CamelCase for variables in other text-based languages that I do.

Well, now that you're programming in Snap!, enjoy the freedom to use multi-word names!

I made a Collatz conjecture grapher: Snap! 6.9.2 Build Your Own Blocks

Thanks. I'm implementing it right now!

EDIT: Oop. There's a problem... Could you help me debug it? Just run the project and turn on 'graphing' by pressing 'g'. Your script is modified and is in the "graph(number)" command block. The problem seems to happen when there is a large number of steps. Even in your project (which is modified to the slightest, shouldn't be a change that causes this), it happens:
Stage
Script:

Can you send a link? In newer versions of python there technically is no number limit other than the amount of memory you have. This (large number test - Replit) works perfectly fine on python.

What is it graphing exactly?

Sorry I've already deleted the REPL. But try this
for i in range(100000000000000000000000):
print(num)

It's graphing the steps it takes to reach the

num is undefined. I tried replacing num with i and it works perfectly fine. See: https://replit.com/@programmeruser/python-number-limits-helping-348663451y

Ah. Sorry. Try:
for num in list(range(100000000000000000000000)):
print(num)

The num part was on my part. I forgot to make the for loop var num instead of i.
The reason we use list() is so that it gives a list from 0 to 100000000000000000000000. Otherwise, if we just put range() it returns 0, 100000000000000000000000.

You're writing the numbers and not going back.

Add a "pos" variable to the script variables block and replace this:
graphcollaz script pic
with this:
graphcollaz script pic (1)

?????

It returns a range object that iterates through the integers in [0, 100000000000000000000000).

You're probably looking at the representation range(0, 100000000000000000000000, 0)

Range objects only store the start, stop, and step.

Run this code:
print('range:")
print(range(100000000000))
print("list and range:")
print(list(range(100000000000)))
See the difference?

>>> for i in range(0, 10, 1):
...     print(i)
... 
0
1
2
3
4
5
6
7
8
9

No, I was confused why you said that range returns 0, 100000000000000000000000

Ah. That seems to fix that problem. But there is still the problem where the graph doesn't go all the way to the right. It stops at the halfway point on the stage.

Does it look like this?: (from my version)


The right half are too small to be seen, they're just a one pixel thick line. (The reason is that my code auto-adjusts the height to fill the stage. That one was made with 10000001 as the i.)

Actually, I think it's just the stage isn't refreshing fast enough. Nevermind.