Can the following function crash?
repeat until x is a positive integer:
x = user input
y = g(x)
return 1 / y
If g crashes, or if 0 in image of positive integers under g
Which of the following is faster?
option 1:
answer = 1
for each i from 1 to x/2
if i divides x evenly, add 1 to answer
return answer
option 2:
answers = [1, 2, 2, 3, 2, 4, 2, 4, 3, 4, 2, 6, 2, 4, 4, 5, 2, 6, 2, 6, 4, 4, 2, 8, 3, 4, 4, 6, 2, 8, 2, 6, 4, 4, 4, 9, 2, 4, 4, 8, 2, 8, 2, 6, 6, 4, 2, 10, 3, 6, 4, 6, 2, 8, 4, 8, 4, 4, 2, 12, 2, 4, 6, 7, 4, 8, 2, 6, 4, 8, 2, 12, 2, 4, 6, 6, 4, 8, 2, 10, 5, 4, 2, 12, 4, 4, 4, 8, 2, 12, 4, 6, 4, 4, 4, 12, 2, 6, 6, 9, 2, 8, 2, 8] -- see https://oeis.org/A000005
if x <= 104:
return the xth entry in answers
else:
answer = 1
for each i from 1 to x/2
if i divides x evenly, add 1 to answer
return answer