Notes

  • Collatz: Asks whether repeating two arithmetic operations will eventually transform every positive integer into 1
    • the Collatz conjecture is one of the most famous unsolved problems in math
  • Hailstone numbers: Sequence of integers generated by Collatz conjecture
  • Iteration: Action or process of iterating or repeating
    • Procedure in which repitition of a sequence of operations yields results successively closer to a desired result
  • Undecidable problems: Problem that hsould give a yes or no answer, but no algorithm exists that can answer correctly on all inputs yet
  • Unsolvable problems: Problem which no algorithm can be written to find the solution
  • Algorithm efficiency: aspect of algorithmic programming that measures amount of steps needed to solve a problem

Hacks

Hack #1

Take the two codes above and combine them so one imput 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. (Algorithm Efficency) (.25)

i = int(input("Enter a number"))
print("Number:", i)

def collatz(i):
    while i > 1:
        print(i, end=' ')
        if (i % 2):
            i = 3*i + 1
            list_.append(i)
        else:
            i = i//2
            list_.append(i)
    print(1, end='')

list_ = [i]
l = list(i)
print('Number of iterations:', len(l) - 1)
print('Sequence: ')
collatz(i)
Number: 10
Number of iterations: 6
Sequence: 
10 5 16 8 4 2 1

Hack #2

The first Algorithm should be efficient while the second should be innefficient. Then explain what distinguishes the efficient from the non-efficient one. (In your own words)

num1 = 10
num2 = 20
num3 = 30
print(num1 + num2 + num3)
60
nums = [10, 20, 30]
print(sum(nums))
60

The first one is an inefficient way to add the sums of variables, because it individually assigns and adds each variable. The second one is more efficient because it uses a list to assign values, and finds the sum with a sum() function.

Hack #3

Explain algorithm efficiency in your own words (.25)

Algorithm Efficiency: making an algorithm more effective by using less lines of code and more resources

Hack #4

Code an efficient program that shows your daily tasks or schedule. (We have an example shown in our lesson) (.25)

tasks = ["wake up", "go to school", "go home", "do homework", "go to sleep"]
 
def dailyRoutine(tasks):
 for task in tasks:
    if task == "wake up":
     print("Good morning!")
    elif task == "go to school":
     print("I hate school.")
    elif task == "go home":
       print("Let's take a nap.")
    elif task == "do homework":
       print("Do your homework... stay on task!")
    else:
        print("Time to sleep.")
 
dailyRoutine(tasks)
Good morning!
I hate school.
Let's take a nap.
Do your homework... stay on task!
Time to sleep.