-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_30.py
65 lines (54 loc) · 1.68 KB
/
level_30.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/env python
# coding=utf-8
# http://repeat:switch@www.pythonchallenge.com/pc/ring/yankeedoodle.html
# Floats, image, formula.
import requests
from PIL import Image
PREFIX = "http://repeat:switch@www.pythonchallenge.com/pc/ring/"
url = PREFIX + 'yankeedoodle.csv'
def factor(n):
"Adapted from http://www.math.utah.edu/~carlson/notes/python.pdf"
d = 2
factors = []
while not n % d:
factors.append(d)
n //= d
d = 3
while n > 1 and d * d <= n:
if not n % d:
factors.append(d)
n //= d
else:
d += 2
if n > 1:
factors.append(n)
return factors
def solve(something):
text = something.replace('\n', ' ').split(', ')
values = [float(p) for p in text]
size = factor(len(values))
im = Image.new("F", size)
im.putdata(values, 256)
im = im.transpose(Image.FLIP_LEFT_RIGHT)
im = im.transpose(Image.ROTATE_90)
im.show()
# n=str(x[i])[5]
# +str(x[i+1])[5]
# +str(x[i+2])[6]
result = []
for i in range(0, len(text), 3):
group = text[i:i + 3]
if len(group) != 3:
break
a, b, c = group
result.append(int(a[5] + b[5] + c[6]))
message = bytes(result).decode()
return message
if __name__ == "__main__":
r = requests.get(url)
something = r.text
answer = solve(something)
print(answer)
# So, you found the hidden message.
# There is lots of room here for a long message, but we only need very little space to say "look at grandpa", so the rest is just garbage.
# http://repeat:switch@www.pythonchallenge.com/pc/ring/grandpa.html