• Home
  • Blog
  • University of California San Diego Collatz Conjecture Project

University of California San Diego Collatz Conjecture Project

0 comments

## 5. COLLATZ CONJECTURE

### This is one of these weird things with numbers that remains unproven, but always works. Collatz had this insight in 1939, but could not prove it, hence it is a conjecture.

### Start with any positive integer. Follow this rule.

### (1) if the integer is even, the next integer is one half of the current integer.

### (2) if the integer is odd, the next integer is 3 times the integer plus one.

### Eventually the sequence of integers will reach 1. This always works!

### Write some python code that generates such a sequence, and terminates at 1. Some hints.

### (1) A while loop should test if the current state of the integer, and exit if the integer has reached 1.

### (2) Remember that the conditional statement n%2 == 0 will return **True** if n is even and **False** if n is odd.

### You code should save the sequence of integers and print it out at the end.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}