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
23
u/PoisonedChips Jul 12 '19
Tf is N(0)
3
u/trimeta Jul 12 '19
Is this supposed to get the Nth element, or all elements from 1 through N? For that matter, my HTML parsing is a bit rusty, but what part of the code is extracting a specific element or set of elements from the sequence, as opposed to dumping the entire thing into "sequence" each time with nothing changing between runs (so either it works the first time or you're caught in an endless loop)?
34
u/[deleted] Jul 12 '19
I tried running this and I got errors:
foo.rb:4: syntax error, unexpected ':'
foo.rb:6: syntax error, unexpected ':', expecting keyword_do_cond or ';' or '\n'
foo.rb:9: syntax error, unexpected end-of-input, expecting keyword_end
7
u/PityUpvote Jul 12 '19
It's O(1), that's the complexity for indexing the sequence and for requesting the webpage in the first place.
1
u/MartianWeedFarmer Jul 12 '19
What the fuck
0
u/[deleted] Jul 12 '19
[deleted] — view deleted comment