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.

2 Comments »

 
 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>