-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_25.py
41 lines (31 loc) · 1.04 KB
/
level_25.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/env python
# coding=utf-8
# http://butter:fly@www.pythonchallenge.com/pc/hex/lake.html
# Splice the wav(image) files.
import wave
from io import BytesIO
import requests
from PIL import Image
PREFIX = "http://butter:fly@www.pythonchallenge.com/pc/hex/"
url = PREFIX + 'lake.html'
def solve():
pieces = []
piece_size = 0
for i in range(25):
r = requests.get(PREFIX + 'lake' + str(i + 1) + '.wav')
f = wave.open(BytesIO(r.content))
frames = f.getnframes() # 10800
piece_size = int((frames // 3) ** .5) # 60
pieces.append(Image.frombytes('RGB', (piece_size, piece_size), f.readframes(frames)))
#
canvas = Image.new('RGB', (piece_size * 5, piece_size * 5))
for i in range(25):
canvas.paste(pieces[i], ((i % 5) * piece_size, (i // 5) * piece_size))
return canvas
def plot(im):
im.show()
if __name__ == "__main__":
answer = solve()
# decent
plot(answer)
# http://butter:fly@www.pythonchallenge.com/pc/hex/decent.html