GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — AdventOfCode/languages/py/2024/22_MonkeyMarket.py at main · wolflu05/AdventOfCode

Expand file tree

/

22_MonkeyMarket.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
52 lines (37 loc) · 962 Bytes
/

22_MonkeyMarket.py

Copy path

File metadata and controls

52 lines (37 loc) · 962 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import collections, itertools
from lib import *
inp = get_input()
def mix_prune(sec, mix_num):
sec = sec ^ mix_num
return sec % 16777216
def sim(sec):
for _ in itertools.count():
sec = mix_prune(sec, sec * 64)
sec = mix_prune(sec, sec // 32)
sec = mix_prune(sec, sec * 2048)
yield sec
p1 = 0
R = []
for l in inp:
l = int(l)
seq = list(itertools.islice(sim(int(l)), 2000))
p1 += seq[-1]
# generate sequence with difference to the previous price for p2
res = []
prev = l % 10
for s in seq:
res.append((s%10,(s%10) - (prev%10)))
prev = s
R.append(res)
print(p1)
C = collections.defaultdict(list)
for d in R:
SEEN = set()
for i in range(3, len(d)):
seq = tuple(d[i-j][1] for j in range(3,-1,-1))
if seq in SEEN:
continue
SEEN.add(seq)
C[seq].append(d[i][0])
m = max(sum(x) for x in C.values())
print(m)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.