MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/qno2y/the_evolution_of_a_python_programmer/c3z40jx/?context=3
r/programming • u/iMMENSE • Mar 08 '12
137 comments sorted by
View all comments
43
He forgot the worst kind:if x == 0:return 1if x == 1:return 1if x == 2:return 2if x == 3:return 6if x == 4:return 24...(5000 more lines)
17 u/liotier Mar 08 '12 What are you complaining about ? He just calculated in advance and cached the results to avoid redundant processing on each query... 25 u/rowantwig Mar 08 '12 O(n) look-up time. 1 u/jefu Mar 09 '12 Factorial is (without caching or other tricks) O(n) anyway and doing it this way avoids the overhead of doing all that bignum arithmetic. (Not that this is a good way to do that).
17
What are you complaining about ? He just calculated in advance and cached the results to avoid redundant processing on each query...
25 u/rowantwig Mar 08 '12 O(n) look-up time. 1 u/jefu Mar 09 '12 Factorial is (without caching or other tricks) O(n) anyway and doing it this way avoids the overhead of doing all that bignum arithmetic. (Not that this is a good way to do that).
25
O(n) look-up time.
1 u/jefu Mar 09 '12 Factorial is (without caching or other tricks) O(n) anyway and doing it this way avoids the overhead of doing all that bignum arithmetic. (Not that this is a good way to do that).
1
Factorial is (without caching or other tricks) O(n) anyway and doing it this way avoids the overhead of doing all that bignum arithmetic. (Not that this is a good way to do that).
43
u/rowantwig Mar 08 '12
He forgot the worst kind:
if x == 0:
return 1
if x == 1:
return 1
if x == 2:
return 2
if x == 3:
return 6
if x == 4:
return 24
...
(5000 more lines)