Hey guys, I am writing a program that needs to output the amount of times a negative number (1-1000) runs through the collatz conjecture. I have a working program for positive numbers because they always go back to 1 and thats when the program terminates. The problem with negative numbers is that the program terminates when the same number is reached 2 times. With -10 it goes through and reaches -10 again and will terminate. However its not always the same as the first with -41 it reaches -122 twice and will then terminate. This is the program I have right now
thats for all n that are elements of the positive integers. Negative integers can not reach 1 because they will never be positive. So what I need to do now is find a way to make it terminate after it repeats a number that it already outputted. I dont know how to have one number from one array match up to many numbers of a different array. I figured if I could put each output into another array y[i] then check before each time an x[i] is put into y[i] to see if it was already put it; if it was the loop terminates.
From what I know about collatz sequence, loop is supposed to stop when the value you are trying to find it's sequence goes to below 1. So your talk of negative numbers should not matter because you are supposed to terminate whatever loop you are using when the value you are checking is below 1
E: And you only need 2 loops, one to generate the numbers and one to find their collatz sequence.
Hint: Don't check positive numbers because when you think of it, they will will always terminate faster than odd values especially the larger they are