Python Challenge(6)
続いてレベル6。
画像からすぐzipが浮かんだけどzip()を使うんだと思ってしまい進まず。
フォーラムを見たら、
It's not that function that's a clue, but something else with the same name.
とあったので、channel.zipをダウンロード。
解凍後のreadme.txtには、
hint1: start from 90052 hint2: answer is inside the zip
とあるのでレベル4と同じ。
import zipfile, re next = '90052' z = zipfile.ZipFile('channel.zip', 'r') while True: line = z.read(next + '.txt').decode() print(line) match = re.search("\d+$", line) if match: next = match.group() else: break z.close()
$ python challenge06.py Next nothing is 94191 Next nothing is 85503 ... Next nothing is 67824 Next nothing is 46145 Collect the comments.
「answer is inside the zip」とあるので、zipファイルのメタデータにコメントってのがあるんだろうと思って調べてみた。
http://docs.python.org/dev/3.0/library/zipfile.html#zipinfo-objectsからZipInfo.commentを使えばおk
import zipfile, re next = '90052' z = zipfile.ZipFile('channel.zip', 'r') ans = [] while True: f = next + '.txt' ans.append(z.getinfo(f).comment.decode()) line = z.read(f).decode() print(line) match = re.search("\d+$", line) if match: next = match.group() else: break print(''.join(ans)) z.close()
$ python challenge06.py Next nothing is 94191 Next nothing is 85503 ... Next nothing is 67824 Next nothing is 46145 Collect the 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 ** ** ** **************************************************************** **************************************************************
hockey.htmlに「it's in the air. look at the letters.」とあるのでoxygen.htmlで〆