Sunday, 24 April 2011

Python Challenge #006 - channel

The zip is a clue. The file can be opened with the zipfiles library.
>>> import re
>>> import sys
>>> import zipfile
>>> n = '90052'
>>> history = []
>>> f = zipfile.ZipFile("channel.zip")
>>> print(f.read(n + '.txt'))
b'Next nothing is 94191'
>>> print(f.getinfo(n + '.txt').comment)
b'*'

This function follows the nothings through the zipped files.
>>> def next_zip(n):
...   history.append(n)
...   text = f.read(n + '.txt').decode()
...   m = re.search('\d+', text)
...   if m is None: return m
...   n = m.group()
...   return n
...

Now collate the file comments in the zip archive in the order of the nothings.
>>> while n: n = next_zip(n)
... 
>>> print(''.join(f.getinfo(n + '.txt').comment.decode() for n in history))
****************************************************************
****************************************************************
**                                                            **
**   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      **
**                                                            **
****************************************************************
 **************************************************************

No comments:

Post a Comment