Compare commits
2 Commits
413a8b50f2
...
e0b88a05b4
| Author | SHA1 | Date | |
|---|---|---|---|
| e0b88a05b4 | |||
| 52623631c7 |
@@ -53,6 +53,7 @@ def p1():
|
||||
|
||||
|
||||
globalgame = 0
|
||||
mdepth = 0
|
||||
def p2():
|
||||
inp = get_input(pw)
|
||||
players = []
|
||||
@@ -67,12 +68,15 @@ def p2():
|
||||
print(players)
|
||||
final = False
|
||||
wins = [0, 0]
|
||||
def play(players):
|
||||
def play(players, depth=0):
|
||||
global globalgame
|
||||
global mdepth
|
||||
mdepth = max(mdepth, depth)
|
||||
globalgame += 1
|
||||
history = set()
|
||||
while all(filter(lambda x: len(x) > 0, players)):
|
||||
hv = ','.join(map(str, players[0])) + ':' + ','.join(map(str, players[1]))
|
||||
hv = frozenset([frozenset(players[0]), frozenset(players[1])])
|
||||
# ','.join(map(str, players[0])) + ':' + ','.join(map(str, players[1]))
|
||||
if hv in history:
|
||||
return 0
|
||||
else:
|
||||
@@ -80,7 +84,7 @@ def p2():
|
||||
i = (players[0].pop(0), players[1].pop(0))
|
||||
if i[0] <= len(players[0]) and i[1] <= len(players[1]):
|
||||
players2 = [players[0][:i[0]], players[1][:i[1]]]
|
||||
won = play(players2)
|
||||
won = play(players2, depth + 1)
|
||||
if won == 1:
|
||||
won = 0
|
||||
else:
|
||||
@@ -99,7 +103,7 @@ def p2():
|
||||
return 1
|
||||
if(len(players[1]) == 0):
|
||||
return 0
|
||||
won = play(players)
|
||||
won = play(players, 1)
|
||||
|
||||
|
||||
if len(players[0]) == 0:
|
||||
@@ -112,7 +116,7 @@ def p2():
|
||||
#print(i,x)
|
||||
su += i*x
|
||||
|
||||
print(su, f'(played games {globalgame})')
|
||||
print(su, f'(played games {globalgame}/{mdepth})')
|
||||
return 0
|
||||
|
||||
result1 = None
|
||||
|
||||
1
day23/data/data.txt
Normal file
1
day23/data/data.txt
Normal file
@@ -0,0 +1 @@
|
||||
962713854
|
||||
1
day23/data/sample.txt
Normal file
1
day23/data/sample.txt
Normal file
@@ -0,0 +1 @@
|
||||
389125467
|
||||
1
day23/index.html
Normal file
1
day23/index.html
Normal file
@@ -0,0 +1 @@
|
||||
404 Not Found
|
||||
122
day23/module.py
Normal file
122
day23/module.py
Normal file
@@ -0,0 +1,122 @@
|
||||
from aoc.input import get_input
|
||||
import copy
|
||||
import itertools
|
||||
import time
|
||||
import collections
|
||||
import re
|
||||
from aoc.partselector import part_one, part_two
|
||||
import functools
|
||||
|
||||
def pw(line):
|
||||
return line.strip()
|
||||
|
||||
def p1():
|
||||
inp = get_input(pw)
|
||||
cups = []
|
||||
for sample in inp:
|
||||
print(sample)
|
||||
cups.append(int(sample))
|
||||
|
||||
def domove(cups, current):
|
||||
current = current % len(cups)
|
||||
selected = (cups+cups)[current+1:current+4]
|
||||
selected_index = sorted([(current+1)%len(cups), (current+2)%len(cups), (current+3)%len(cups)], reverse=True)
|
||||
print(cups)
|
||||
origcurrent = cups[current]
|
||||
targetid = cups[current] - 1
|
||||
print(current, cups[current], selected, targetid)
|
||||
for c in selected_index:
|
||||
cups.pop(c)
|
||||
target = None
|
||||
if targetid == 0:
|
||||
targetid = 9
|
||||
while target == None:
|
||||
try:
|
||||
target = cups.index(targetid)
|
||||
except:
|
||||
targetid = (targetid - 1)
|
||||
print('-', targetid)
|
||||
if targetid == 0:
|
||||
targetid = 9
|
||||
if targetid < -1:
|
||||
break
|
||||
print('-', targetid)
|
||||
print('destination', targetid, target, cups)
|
||||
cups.insert(target + 1, selected[-1])
|
||||
cups.insert(target + 1, selected[-2])
|
||||
cups.insert(target + 1, selected[-3])
|
||||
|
||||
while not cups[current] == origcurrent:
|
||||
cups = cups[1:] + cups[0:1]
|
||||
print(cups)
|
||||
return cups
|
||||
|
||||
|
||||
current = 0
|
||||
for i in range(5):
|
||||
cups = domove(cups, current)
|
||||
current += 1
|
||||
cups = cups
|
||||
cupss = ''.join(map(str,cups))
|
||||
print(cupss)
|
||||
a, b = cupss.split('1')
|
||||
print(b + a)
|
||||
return inp
|
||||
|
||||
|
||||
def p2():
|
||||
inp = get_input(pw)
|
||||
cups = collections.deque()
|
||||
for sample in inp:
|
||||
cups.append(int(sample))
|
||||
|
||||
total = 1_000_000
|
||||
|
||||
for cc in range(10, 1_000_000+1):
|
||||
cups.append(cc)
|
||||
|
||||
backup = collections.defaultdict(list)
|
||||
def fixnext():
|
||||
next_ = cups.popleft()
|
||||
# ok, now is the time to put these values back
|
||||
if next_ in backup:
|
||||
cups.extendleft(reversed(backup[next_]))
|
||||
del backup[next_]
|
||||
return next_
|
||||
|
||||
def domove():
|
||||
current = fixnext()
|
||||
selected = [fixnext(), fixnext(), fixnext()]
|
||||
unavailable = set([0, current] + selected)
|
||||
|
||||
# find dest
|
||||
target = current - 1
|
||||
while target in set(unavailable):
|
||||
target -= 1
|
||||
if target < 1:
|
||||
target = total
|
||||
backup[target] += selected
|
||||
cups.append(current)
|
||||
|
||||
for _ in range(10_000_000):
|
||||
domove()
|
||||
|
||||
while (next_ := fixnext()) != 1:
|
||||
cups.append(next_)
|
||||
a, b = fixnext(), fixnext()
|
||||
print(a*b)
|
||||
return inp
|
||||
|
||||
result1 = None
|
||||
if part_one():
|
||||
start = time.time()
|
||||
result1 = p1()
|
||||
print(round(1000*(time.time() - start), 2), 'ms')
|
||||
|
||||
|
||||
if part_two():
|
||||
start = time.time()
|
||||
p2()
|
||||
print(round(1000*(time.time() - start), 2), 'ms')
|
||||
|
||||
|
||||
599
day24/data/data.txt
Normal file
599
day24/data/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
20
day24/data/sample.txt
Normal file
20
day24/data/sample.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
sesenwnenenewseeswwswswwnenewsewsw
|
||||
neeenesenwnwwswnenewnwwsewnenwseswesw
|
||||
seswneswswsenwwnwse
|
||||
nwnwneseeswswnenewneswwnewseswneseene
|
||||
swweswneswnenwsewnwneneseenw
|
||||
eesenwseswswnenwswnwnwsewwnwsene
|
||||
sewnenenenesenwsewnenwwwse
|
||||
wenwwweseeeweswwwnwwe
|
||||
wsweesenenewnwwnwsenewsenwwsesesenwne
|
||||
neeswseenwwswnwswswnw
|
||||
nenwswwsewswnenenewsenwsenwnesesenew
|
||||
enewnwewneswsewnwswenweswnenwsenwsw
|
||||
sweneswneswneneenwnewenewwneswswnese
|
||||
swwesenesewenwneswnwwneseswwne
|
||||
enesenwswwswneneswsenwnewswseenwsese
|
||||
wnwnesenesenenwwnenwsewesewsesesew
|
||||
nenewswnwewswnenesenwnesewesw
|
||||
eneswnwswnwsenenwnwnwwseeswneewsenese
|
||||
neswnwewnwnwseenwseesewsenwsweewe
|
||||
wseweeenwnesenwwwswnew
|
||||
1
day24/index.html
Normal file
1
day24/index.html
Normal file
@@ -0,0 +1 @@
|
||||
404 Not Found
|
||||
153
day24/module.py
Normal file
153
day24/module.py
Normal file
@@ -0,0 +1,153 @@
|
||||
from aoc.input import get_input
|
||||
import copy
|
||||
import itertools
|
||||
import time
|
||||
import collections
|
||||
import re
|
||||
from aoc.partselector import part_one, part_two
|
||||
import functools
|
||||
|
||||
def pw(line):
|
||||
return line.strip()
|
||||
|
||||
def p1():
|
||||
inp = get_input(pw)
|
||||
directions = {
|
||||
# e,w 101
|
||||
# ne, sw 101
|
||||
# 101
|
||||
"e": [1,0,-1],
|
||||
"w": [-1,0,1],
|
||||
"nw": [0,-1,1],
|
||||
"se": [0,1,-1],
|
||||
"ne": [1,-1,0],
|
||||
"sw": [-1,1,0],
|
||||
}
|
||||
i2 = []
|
||||
for sample in inp:
|
||||
cnt = 0
|
||||
steps = []
|
||||
|
||||
while cnt < len(sample):
|
||||
if sample[cnt] in directions:
|
||||
steps.append(directions[sample[cnt]])
|
||||
cnt += 1
|
||||
elif sample[cnt:cnt+2] in directions:
|
||||
steps.append(directions[sample[cnt:cnt+2]])
|
||||
cnt += 2
|
||||
i2.append(steps)
|
||||
|
||||
b = collections.defaultdict(lambda: 0)
|
||||
for n in i2:
|
||||
c = [0,0,0]
|
||||
for s in n:
|
||||
c[0] += s[0]
|
||||
c[1] += s[1]
|
||||
c[2] += s[2]
|
||||
print(c)
|
||||
b[tuple(c)] += 1
|
||||
count = 0
|
||||
for x in b.values():
|
||||
if x%2 == 1:
|
||||
count += 1
|
||||
print(count)
|
||||
|
||||
return inp
|
||||
|
||||
|
||||
def p2():
|
||||
inp = get_input(pw)
|
||||
directions = {
|
||||
# e,w 101
|
||||
# ne, sw 101
|
||||
# 101
|
||||
"e": tuple([1,0,-1]),
|
||||
"w": tuple([-1,0,1]),
|
||||
"nw": tuple([0,-1,1]),
|
||||
"se": tuple([0,1,-1]),
|
||||
"ne": tuple([1,-1,0]),
|
||||
"sw": tuple([-1,1,0]),
|
||||
}
|
||||
i2 = []
|
||||
for sample in inp:
|
||||
cnt = 0
|
||||
steps = []
|
||||
|
||||
while cnt < len(sample):
|
||||
if sample[cnt] in directions:
|
||||
steps.append(directions[sample[cnt]])
|
||||
cnt += 1
|
||||
elif sample[cnt:cnt+2] in directions:
|
||||
steps.append(directions[sample[cnt:cnt+2]])
|
||||
cnt += 2
|
||||
i2.append(steps)
|
||||
|
||||
b = collections.defaultdict(lambda: 0)
|
||||
for n in i2:
|
||||
c = [0,0,0]
|
||||
for s in n:
|
||||
c[0] += s[0]
|
||||
c[1] += s[1]
|
||||
c[2] += s[2]
|
||||
b[tuple(c)] = (b[tuple(c)]+1)%2
|
||||
|
||||
count = 0
|
||||
for x in b.values():
|
||||
if x%2 == 1:
|
||||
count += 1
|
||||
print(count)
|
||||
|
||||
minx = min(map(lambda x: x[0], b.keys()))
|
||||
maxx = max(map(lambda x: x[0], b.keys()))
|
||||
miny = min(map(lambda x: x[1], b.keys()))
|
||||
maxy = max(map(lambda x: x[1], b.keys()))
|
||||
minz = min(map(lambda x: x[2], b.keys()))
|
||||
maxz = max(map(lambda x: x[2], b.keys()))
|
||||
|
||||
def iterate2():
|
||||
b2 = collections.defaultdict(lambda: 0)
|
||||
for oc,v in b.items():
|
||||
x,y,z = oc
|
||||
if v == 1:
|
||||
for s in directions.values():
|
||||
c = tuple([x+s[0], y+s[1], z+s[2]])
|
||||
b2[c] += 1
|
||||
for c, x in b2.items():
|
||||
if x == 2 and b[c] == 0:
|
||||
b[c] = 1
|
||||
elif (x == 0 or x > 2) and b[c] == 1:
|
||||
b[c] = 0
|
||||
|
||||
|
||||
for i in range(100):
|
||||
iterate2()
|
||||
count = 0
|
||||
for x in b.values():
|
||||
if x%2 == 1:
|
||||
count += 1
|
||||
print(i+1, count)
|
||||
break
|
||||
|
||||
|
||||
count = 0
|
||||
for x in b.values():
|
||||
if x%2 == 1:
|
||||
count += 1
|
||||
print(count)
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
result1 = None
|
||||
if part_one():
|
||||
start = time.time()
|
||||
result1 = p1()
|
||||
print(round(1000*(time.time() - start), 2), 'ms')
|
||||
|
||||
|
||||
if part_two():
|
||||
start = time.time()
|
||||
p2()
|
||||
print(round(1000*(time.time() - start), 2), 'ms')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user