|
| 1 | +from collections import * |
| 2 | +from itertools import * |
| 3 | +from functools import * |
| 4 | +import numpy as np |
| 5 | +import networkx as nx |
| 6 | +# import z3 |
| 7 | +import re |
| 8 | +import sys |
| 9 | +sys.setrecursionlimit(1000000) |
| 10 | + |
| 11 | +s1 = s2 = 0 |
| 12 | +# coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())} |
| 13 | + |
| 14 | +d4 = [1, 1j, -1, -1j] |
| 15 | +d8 = d4 + [1+1j, 1-1j, -1+1j, -1-1j] |
| 16 | +d4half = [i/2 for i in d4] |
| 17 | +d8half = [i/2 for i in d8] |
| 18 | +def adjacent(coord, dirs=d4): |
| 19 | + return [coord + d for d in dirs] |
| 20 | + |
| 21 | +# G = nx.Graph() |
| 22 | +# for c in coords: |
| 23 | +# for d in [1, 1j, -1, -1j]: |
| 24 | +# if coords[c] != '#' != coords[c+d]: |
| 25 | +# G.add_edge(c, c+d) |
| 26 | + |
| 27 | +# S = [c for c in coords if coords[c] in 'S'][0] |
| 28 | +# coord_to_dist = nx.shortest_path_length(G, S).items() |
| 29 | + |
| 30 | + |
| 31 | + # Calculate the result of multiplying the secret number by 64. Then, mix this result into the secret number. Finally, prune the secret number. |
| 32 | + # Calculate the result of dividing the secret number by 32. Round the result down to the nearest integer. Then, mix this result into the secret number. Finally, prune the secret number. |
| 33 | + # Calculate the result of multiplying the secret number by 2048. Then, mix this result into the secret number. Finally, prune the secret number. |
| 34 | + |
| 35 | +def secret(num): |
| 36 | + mod10 = [] |
| 37 | + price = [] |
| 38 | + print(num) |
| 39 | + for i in range(2000): |
| 40 | + prev = num |
| 41 | + num ^= num * 64 |
| 42 | + num %= 16777216 |
| 43 | + num ^= num // 32 |
| 44 | + num %= 16777216 |
| 45 | + num ^= num * 2048 |
| 46 | + num %= 16777216 |
| 47 | + mod10.append((num%10 - prev%10)) |
| 48 | + price.append(num%10) |
| 49 | + # print(f"{num} {num%10=} {num%10-prev%10=}") |
| 50 | + return mod10, price |
| 51 | + |
| 52 | + |
| 53 | +c = Counter() |
| 54 | +for line in open(0): |
| 55 | + n = int(line) |
| 56 | + # s1 += secret(n) |
| 57 | + a, price = secret(n) |
| 58 | + # print(a[:20]) |
| 59 | + # print(price[:20]) |
| 60 | + seen = set() |
| 61 | + for i, (t, p) in enumerate(zip(zip(a, a[1:], a[2:], a[3:]), price[3:])): |
| 62 | + if t not in seen: |
| 63 | + seen.add(t) |
| 64 | + c[t] += p |
| 65 | + # exit() |
| 66 | +print(c.most_common(20)) |
| 67 | +print(c[(-2,1,-1,3)]) |
| 68 | + |
| 69 | + |
| 70 | + # re.findall(r"\d+", line) |
| 71 | + |
| 72 | + |
| 73 | +print(s1, s2, sep="\n") |
0 commit comments