[閱讀全文]
Andy started with 9, 3 and 100 manually after I showed him the rules with sample initial value 5. He is strong in mental calculation since he made not a single mistake when writing down the following.
Collatz Conjecturelet's start from an integer 5 5, ?, ?, ?, ?, if the previous one is even, then the new number = previous one divided by 2 odd, then the new number = 3 * "previous one" + 1 5, 16, 8, 4, 2, 1 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 3, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1 100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34,
Collatz Conjecture is one of the hardest math problems in front of our human being. No one can prove it (any number will stop at 1 eventually) even today.
This is the first time we met while loop.
func testCollatz() { // 13 % 5 = 3, 13 % 2 = 1, 42 % 2 = 0 var c = 1000000 while c != 1 { print("(c), ", terminator: "") if c % 2 == 1 { c = 3 * c + 1 } else { c = c / 2 } }}
And at the end of class our program generated the long series for 1000000:
...
[閱讀全文]