Skip to content

Commit 371b112

Browse files
committed
Solve ivanr3d.com/projects/pi
1 parent 65fd961 commit 371b112

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

ivanr3d.pi/2024.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import itertools
2+
import string
3+
4+
encoded = "Wii kxtszof ova fsegyrpm d lnsrjkujvq roj! Kdaxii svw vnwhj pvugho buynkx tn vwh-gsvw ruzqia. Mrq'x kxtmjw bx fhlhlujw cjoq! Hmg tyhfa gx dwd fdqu bsm osynbn oulfrex, kahs con vjpmd qtjv bx whwxssp cti hmulkudui yqg f Miywh Sj Efh!"
5+
pi = "3141592653589793"
6+
7+
out = ""
8+
for letter, shift in zip(encoded.lower(), itertools.cycle(pi)):
9+
if letter.isalpha():
10+
out += string.ascii_lowercase[(string.ascii_lowercase.index(letter.lower()) + 26 - int(shift)) % 26]
11+
else:
12+
out += letter
13+
print(out)
14+
15+
numbers = "zero one two three four five size seven eight nine ten".split()
16+
result = 1
17+
out = "".join(i for i in out if i.isalpha())
18+
for i in range(len(out)):
19+
for idx, num in enumerate(numbers):
20+
if out[i:].startswith(num):
21+
result *= idx
22+
print(result)

ivanr3d.pi/2025.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import string
2+
3+
4+
def solve(pi, data):
5+
# 32 digits of pi.
6+
digits = str(pi).replace(".", "")[:32]
7+
8+
# Find entries with a price which is in pi.
9+
corrupt = []
10+
for line in data.splitlines()[1:]:
11+
day, price, ticker = line.split()
12+
if price.replace(".", "") in digits:
13+
corrupt.append((int(day), float(price), ticker))
14+
15+
# Part one. Collect correupt prices.
16+
val = corrupt[0][1]
17+
for day, price, ticker in corrupt:
18+
if day % 2 == 0:
19+
val *= price
20+
else:
21+
val /= price
22+
23+
val = int(str(val).replace(".", ""))
24+
print(str(val)[:10])
25+
26+
# Part two.
27+
28+
# Map ticker to day and price for lookups.
29+
tick_prices = {}
30+
for line in data.splitlines()[1:]:
31+
day, price, ticker = line.split()
32+
tick_prices[ticker] = (int(day), int(str(price).replace(".", "")))
33+
# Load the cipher_map into a list.
34+
cipher_map = [i for line in CIPHER_MAP_TXT.splitlines() for i in line.split()]
35+
36+
phrase = []
37+
for day, price, ticker in corrupt:
38+
shift = int(str(price).replace(".", ""))
39+
other_ticker = "".join(
40+
string.ascii_uppercase[(string.ascii_uppercase.index(i) + shift) % 26]
41+
for i in ticker
42+
)
43+
other_day, other_price = tick_prices[other_ticker]
44+
letter = cipher_map[other_price % 256]
45+
phrase.append((other_day, letter))
46+
print("".join(i for _, i in sorted(phrase)))
47+
48+
49+
DATA = """\
50+
Day Price ($) Ticker
51+
1 150.00 TLM
52+
2 93.23 PIH
53+
3 300.50 MTH
54+
4 420.75 IUV
55+
5 3.14 GST
56+
6 720.20 FKE
57+
7 12.57 KVW
58+
8 88.90 TEC
59+
9 210.00 OIL
60+
10 2.64 PHI
61+
11 45.60 CUV
62+
12 33.83 SPI
63+
13 999.99 MEME
64+
14 28.27 MED
65+
15 123.45 BIA
66+
16 65.80 REN
67+
17 6.53 HST
68+
18 250.00 AND
69+
19 18.85 YVO
70+
20 33.33 XOR
71+
21 8.46 NUM
72+
22 777.77 POT
73+
23 9.42 BNO
74+
24 199.99 NOT
75+
25 15.92 SPI
76+
26 850.00 VSL
77+
27 19.94 IVA
78+
28 58.97 GST
79+
29 27.95 PHI
80+
30 21.99 EXW
81+
"""
82+
83+
CIPHER_MAP_TXT = """\
84+
X J P Z Q T M C A O W Y B G D A
85+
N F R S H V K U E X J P Z Q T M
86+
C L O W Y B G D A N F R S H V K
87+
G E X J P Z Q T M P L O W Y B G
88+
D A N F R S H V K U E X J P Z Q
89+
T M A L O W Y B G D A O F I S H
90+
A K U E X J P Z Q T M C L O W Y
91+
O G D A N F R S H V K U E X J P
92+
Y Q T M C L O W Y B G D A N F R
93+
S H V K U E X Y G Z Q T M C L O
94+
D Y B G D A N F R S H V K U D X
95+
J P Z Q T M C L O W Y B G D A N
96+
F R S H V K U E X J P Z Q T M C
97+
D O W Y B G D A N F R S H V K U
98+
E X J P Z Q T M C O O W Y B G D
99+
A N F R S H V K U E X J P Z Q T"""
100+
101+
102+
if __name__ == "__main__":
103+
solve("314159265358979323846264338327950288419716939937510", DATA)
104+
105+

0 commit comments

Comments
 (0)