3.17 and 3.18 Algorithmic Efficiency/Undecidable Problems
HW 9
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)
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)
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)