-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.py
executable file
·33 lines (26 loc) · 929 Bytes
/
04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
import re
import string
import utils
url = "http://www.pythonchallenge.com/pc/def/linkedlist.html"
url = "http://www.pythonchallenge.com/pc/def/linkedlist.php"
url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345"
if __name__ == "__main__":
value_pattern = re.compile(r'and the next nothing is (\d+)')
this_value = url[-5:]
count = 0;
while count <= 400:
source = utils.wget(url)
#print "%d: %s" % (count, source)
mo = re.search(value_pattern, source)
if mo:
next_value = mo.group(1)
elif source.find('Divide by two') >= 0:
next_value = str(int(this_value) / 2)
else:
print "%d: %s" % (count, source)
break
url = url.replace(this_value, next_value)
this_value = next_value
count += 1
print utils.update_url(url, utils.return_this, source)