Skip to content

Instantly share code, notes, and snippets.

@wacotaqo
Created January 21, 2009 21:51
Show Gist options
  • Select an option

  • Save wacotaqo/50232 to your computer and use it in GitHub Desktop.

Select an option

Save wacotaqo/50232 to your computer and use it in GitHub Desktop.
Python Challenge #6
===================
URL: http://www.pythonchallenge.com/pc/def/channel.html
Title: Now there are pairs
Going to http://www.pythonchallenge.com/pc/def/jeans.html
Reply: Zoom in
This was by far the hardest problem for me.
Took ages before I finally realised how to get by the first zip issue.
But a tip on the forum helped: "Challenge 4 is to php as challenge 6 is to ..."
All other (verb) the (noun) tips didn't work for me.
Once I got the channel.zip file, I unpacked it. Rushed and missed the readme. SO i started with the first file, which lead me astray for 2 hrs.
Finally, the readme help to get the right starting number. The rest is the linkedlist (with files) solution from puzzle 4 and the ascii text solution from puzzle 5.
def pc6_part2():
import zipfile
import re
zfn = r'c:\temp\channel.zip'
zf = zipfile.ZipFile(zfn, 'r')
fnTemplate = '%s.txt'
zfl = zf.filelist
nothing = 90052 #re.match('[nN]ext nothing is ([0123456789]*)', zf.read(zfl[0].filename)).groups()[0]
lastNothing = None
comments = []
data = ''
while nothing:
data = zf.read(fnTemplate%nothing)
comments.append(zf.getinfo(fnTemplate%nothing).comment)
nextMatch = re.match('[nN]ext nothing is ([0123456789]*)', data)
lastNothing = nothing
if nextMatch:
nothing = nextMatch.groups()[0]
else:
nothing = None
return (nothing, lastNothing, data, comments)
****************************************************************
****************************************************************
** **
** OO OO XX YYYY GG GG EEEEEE NN NN **
** OO OO XXXXXX YYYYYY GG GG EEEEEE NN NN **
** OO OO XXX XXX YYY YY GG GG EE NN NN **
** OOOOOOOO XX XX YY GGG EEEEE NNNN **
** OOOOOOOO XX XX YY GGG EEEEE NN **
** OO OO XXX XXX YYY YY GG GG EE NN **
** OO OO XXXXXX YYYYYY GG GG EEEEEE NN **
** OO OO XX YYYY GG GG EEEEEE NN **
** **
****************************************************************
**************************************************************
New URL: http://www.pythonchallenge.com/pc/def/hockey.html
But it was wrong. This gives: "Its in the air, look at the letters."
I had to look an extra time to see it...
New URL: http://www.pythonchallenge.com/pc/def/oxygen.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment