I'm trying to develop a program that running the first n integers through the "Collatz Conjecture function", denoted as "c(x)", where any odd number is updated to thrice itself plus 1, and any even number is updated to half of itself, and it runs this until the number gets updated to 1. This is simply as a programming exercise. I'm not looking to prove anything with this. I just wanted to learn about optimizations such as bit manipulation.
In order to speed up the process I made it create a list of every unique number it generates through this function, and if it generates a previously generated number then it moves onto the next input. This creates the problem, however, of taking loads of time checking each element in my list (called "nums") every time it runs the function again.
The code I used for it looks like this:
if x not in nums:
nums.append(int(x))
c(x)
Is there a way to make checking this list for already-generated numbers any faster? Or is there maybe a totally different way that removes the need for the list and/or checking every element altogether? Once you start getting above n = 100,000 (meaning 100,000 starting inputs) checking the list takes a noticeably longer time, and any optimization could cut out an entire hour of calculating for larger values of n.