Python Challenge level 4: “follow the chain”
Level 4 requires some web scraping. Nice :)
Hint 1: urllib may help. DON’T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough
Hint 2: linkedlist.php?nothing=12345
import urllib,re
url='http://www.pythonchallenge.com/pc/def/
linkedlist.php?nothing='
seed="12345"
for i in range(400):
text=urllib.urlopen(url+seed).read()
seed="".join(re.findall(r"nothing is (\d+)",text))
try :
int(seed)
print " Next:",seed
except :
print " Last:",text
break
When we get to 92118 the message is:
Yes. Divide by two and keep going.
So we’ll reset the seed to 46059
peak
Great. To Level 5.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
shouldn’t the regex be r”nothing is (\d+)”
???
Yes it should. Somehow it got deleted after copying&pasting. Thanks for the catch ;-)