Notes

  • Hailstone numbers are undeciable and always end with 4 2 1

Vocab

  • Collatz: The Collatz conjecture is one of the most famous unsolved problems in mathematics. The conjecture asks whether repeating two simple arithmetic operations will eventually transform every positive integer into 1.

  • Hailstone numbers: The sequence of integers generated by Collatz conjecture are called Hailstone Numbers. Examples: Input : N = 7 Output : Hailstone Numbers: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 No.

  • Iteration: The action or a process of iterating or repeating: such as. : a procedure in which repetition of a sequence of operations yields results successively closer to a desired result.

  • Undecidable problems: An undecidable problem is one that should give a "yes" or "no" answer, but yet no algorithm exists that can answer correctly on all inputs.

  • Unsolvable problems: An unsolvable problem is one for which no algorithm can ever be written to find the solution.

Hacks Unit 3 Section 18

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

while True:
    try:
        i = int(input('Enter i: '))
        break
    except ValueError:
        print('Invalid selection, try again: ', end='')

l = collatz(i)

print('')
print('Collatz sequence:', l)
print('Number of iterations:', len(l) - 1)
Collatz sequence: [12, 6.0, 3.0, 10.0, 5.0, 16.0, 8.0, 4.0, 2.0, 1.0]
Number of iterations: 9

Hacks for Unit 3 Section 17

Inaficent Way to sort letters

  • Makes a varible for each Food
  • Then puts them into a list
  • On a larger Data Scale this would take longer
  • This one took 7.6 seconds
def food():
    Food1 = "pizza"
    Food2 = input("Input a food")
    Food3 = input("Input a food")
    foods = (Food1, Food2, Food3)
    for i in foods:
        if i == "pizza":
            print("there is pizza")
    return foods


result = food()
print(result)
there is pizza
('pizza', 'sprite', 'chips')

More efficent way

  • Only has one varible that list each food
  • Doesn't need to be put in a list
  • Works better on a larger scale
  • Only takes 4.1 seconds
def fast():
    foods = ("pizza", input("Input a food"), input("Input a food"))
    for i in foods:
        if i == "pizza":
            print("there is pizza")
    return foods

result = fast()
print(result)
there is pizza
('pizza', 'sprite', 'chips')