Page 1 of 1

Collatz and Raspberry Pi

Posted: Wed May 02, 2018 6:01 pm
by mcjhn
Hi,
My class enjoyed learning about the collatz conjecture from this numberphiile video...
https://www.youtube.com/watch?v=5mFpVDpKX70
Its quite easy to do a few examples with pen and paper then create a scratch and/python program to make things go faster.
My scratch code
Image
My Python code

Code: Select all

from time import sleep
n = 7
while True:
    sleep(0.01)
    if (n % 2): 
        n = 3 * n + 1
        print(n)
    else:
        n = n // 2
        print(n)
Mark

Re: Collatz and Raspberry Pi

Posted: Thu May 03, 2018 3:31 am
by ejolson
mcjhn wrote:
Wed May 02, 2018 6:01 pm
My class enjoyed learning about the collatz conjecture from this numberphiile video...
Thanks for posting the code examples, especially the scratch version. There was another discussion on the collatz algorithm about a year ago on this forum which focused on readability of code and efficiency. I suspect you might find it interesting to read.