3.17 and 3.18 Hacks
These are my 3.17 and 3.18 Hacks.
Vocab
- Collatz: A conjecture that asks whether repeating two simple arithmetic operations will eventually transform every positive integer into 1.
- Hailstone numbers: A squence of integers generated by the Collatz conjecture.
- Undecidable problems: one that should give a "yes" or "no" answer, but yet no algorithm exists that can correctly answer on all outputs
- Unsolvable problems: one for which no algorithm can ever be written to find the solution
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)
## the number is 10, the number of iterations is 6, and the sequence is 10,5,16,8,4,2,1
num1 = 10
num2 = 20
num3 = 30
print(num1 + num2 + num3)
nums = [10, 20, 30]
print(sum(nums))
The second algorithm is more efficient than the first because the second uses less lines of code (it did not individually assigns and adds each number in the list).
tasks = ["review notes", "do practice problems", "ask teacher questions"]
def complete_tasks(tasks):
for task in tasks:
# code to complete each task goes here
if task == "wake up":
print("Reviewing Confidence intervals")
elif task == "do practice problems":
print("Doing practice problems now!")
elif task == "ask teacher questions":
print("Asking questions now!")
# and so on for each task in the list
# call the function to complete the tasks
complete_tasks(tasks)