Skip to content

Instantly share code, notes, and snippets.

@shionryuu
Created January 22, 2016 16:35
Show Gist options
  • Save shionryuu/0e9a6de7178a00420d43 to your computer and use it in GitHub Desktop.
Save shionryuu/0e9a6de7178a00420d43 to your computer and use it in GitHub Desktop.
Python Challenge 04
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# http://www.pythonchallenge.com/pc/def/linkedlist.php
import urllib, re
uri = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s'
nothing = '12345' # '8022'
pattern = 'and the next nothing is (\d+)'
while True:
try:
content = urllib.urlopen(uri % nothing).read()
print content
nothing = re.search(pattern, content).group(1)
# print nothing
except AttributeError:
# AttributeError: 'NoneType' object has no attribute 'group'
# if you see 'Yes. Divide by two and keep going.', just div
# the latest nothing by 2 and try again.
break
print nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment