r/shittyprogramming • • Jul 12 '19
This is technically N(0), amirite?
import requests
from lxml import html
def fibonacci(n):
sequence = ()
while n >= len(sequence):
sequence_html = html.fromstring(requests.get('https://oeis.org/A000045').content)
sequence = sequence_html.xpath('//tt/text()')[0].split(', ')
return int(sequence[n])
107
Upvotes
View all comments
Show parent comment
2
u/Kopachris Jul 12 '19
Common entry-level programming challenge is to code a recursive function to calculate the Nth Fibonacci number, or the numbers through N. This teaches about time complexity, or the Big O.
This "genius"s solution is not recursive and so technically this code has lower time complexity, but requires making an HTTP request which itself is a fairly complex operation underneath, making it an amusing paradox.
But you were probably being rhetorical and didn't actually need or want an explanation?