Essential Knowledge

Collatz: Famous unsolved problem in math, and asks whether repeating two simple arithmetic operations will eventually transform every positive integer into 1

Hailstone Numbers: sequence of integers generated by Collatz

Undecidable Problems: gives "yes" or "no" answer, but no algorithm can correctly answer inputs

Unsolvable Problems: No algorithm can ever be written to find the solution

Algorithm Efficiency: Measures number of steps needed to solve a problem

Heuristic Approach: Shortest and most efficient "route"


Hailstone

Take the two codes above and combine them so one input gives the output that contains both the hailstone numbers and the number of iterations it takes i = 1. The more efficient the code, the higher your grade will be.

def collatz(i):
    while i != 1:
        if i % 2 > 0:
             i =((3 * i) + 1)
             list_.append(int(i))
        else:
            i = (i / 2)
            list_.append(int(i))
    return list_


print('Please enter a number: ', end='' + "\n")
while True:
    try:
        i = int(input())
        list_ = [i]
        break
    except ValueError:
        print('Invaid selection, try again: ', end='')


l = collatz(i)

print('Sequence: ')
print(*l, sep=" ")
print('Number of iterations:', len(l) - 1)
Please enter a number: 
Sequence: 
9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Number of iterations: 19

Effective

  • Write 2 algorithms: One is efficent and one is innefficent, then explain why one is efficent while the other isn't.
  • Explain why one algorithm is more efficient than another using mathematical and/or formal reasoning.
  • use variables, if statements, and loops to program your algorithm and upload to jupyter notebooks/ fastpages.
tasks = ["a", "b", "c"]
# the tasks / variables
def complete_tasks(tasks):
 for task in tasks:
# completing each task
 
   if task == "a":
     print("a")
   elif task == "b":
     print("b")
   elif task == "c":
       print("c")
# calling the function
complete_tasks(tasks)
a
b
c
tasks = ["a", "b", "c"]
tasks.sort ()
print (tasks)
['a', 'b', 'c']

Daily Tasks

tasks = ["shower", "brush teeth", "skincare", "sleep"]
 
def complete_tasks(tasks):
    for task in tasks:
        if task == "shower":
            print("Take a shower!")
        elif task == "brush teeth":
            print("Go brush your teeth!")
        elif task == "skincare":
            print("Do your skincare!")
        elif task == "sleep":
            print("Go to bed!")

complete_tasks(tasks)
Take a shower!
Go brush your teeth!
Do your skincare!
Go to bed!