mcjhn
Posts: 2
Joined: Mon Jul 27, 2015 3:57 pm

Collatz and Raspberry Pi

Wed May 02, 2018 6:01 pm

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
Attachments
scratch.jpg
scratch.jpg (33.24 KiB) Viewed 711 times

ejolson
Posts: 1832
Joined: Tue Mar 18, 2014 11:47 am

Re: Collatz and Raspberry Pi

Thu May 03, 2018 3:31 am

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.

Return to “Teaching and learning resources”

Who is online

Users browsing this forum: No registered users and 3 guests