diff --git a/day14/input b/day14/input new file mode 100644 index 0000000..b016c34 --- /dev/null +++ b/day14/input @@ -0,0 +1,500 @@ +p=18,60 v=90,-17 +p=4,66 v=-43,10 +p=88,50 v=19,62 +p=33,42 v=99,-68 +p=8,85 v=78,-29 +p=49,78 v=-1,-52 +p=39,73 v=8,-18 +p=61,8 v=34,-12 +p=82,84 v=19,-1 +p=4,86 v=71,-32 +p=23,99 v=5,33 +p=68,3 v=17,74 +p=84,56 v=78,89 +p=38,74 v=15,27 +p=34,55 v=-85,24 +p=78,41 v=-61,-6 +p=34,58 v=40,-79 +p=23,96 v=-87,81 +p=2,31 v=-72,-95 +p=46,88 v=16,-87 +p=32,65 v=47,-55 +p=56,69 v=1,-76 +p=24,86 v=90,40 +p=87,4 v=-53,14 +p=30,38 v=56,-99 +p=64,37 v=-76,-81 +p=93,51 v=-98,-96 +p=14,4 v=-5,95 +p=46,101 v=-36,-5 +p=83,61 v=79,45 +p=31,11 v=78,19 +p=42,85 v=-27,92 +p=0,30 v=-97,-71 +p=51,76 v=50,99 +p=89,30 v=76,-62 +p=98,8 v=-45,93 +p=19,101 v=-27,68 +p=62,30 v=-27,-79 +p=62,72 v=-66,-24 +p=51,68 v=-68,68 +p=42,34 v=66,-20 +p=81,14 v=-6,-91 +p=69,82 v=83,22 +p=11,66 v=98,-18 +p=23,81 v=-41,6 +p=53,48 v=-31,55 +p=81,46 v=-39,28 +p=49,7 v=24,-53 +p=44,22 v=15,-42 +p=6,24 v=-20,63 +p=35,43 v=22,38 +p=31,23 v=15,22 +p=92,74 v=-73,71 +p=29,70 v=39,17 +p=81,62 v=52,-49 +p=96,65 v=-57,-9 +p=36,70 v=82,34 +p=45,67 v=7,14 +p=27,79 v=-3,88 +p=64,26 v=85,-78 +p=45,85 v=75,92 +p=65,97 v=68,-53 +p=20,100 v=-85,-6 +p=80,23 v=-57,97 +p=81,3 v=-32,91 +p=95,18 v=-22,19 +p=28,61 v=98,24 +p=17,57 v=-3,-55 +p=25,67 v=-20,96 +p=44,4 v=83,-60 +p=98,26 v=-81,11 +p=83,55 v=-14,-37 +p=50,55 v=61,1 +p=76,90 v=55,-34 +p=14,49 v=64,93 +p=20,8 v=39,-81 +p=20,88 v=98,85 +p=75,4 v=-43,-16 +p=55,18 v=-93,15 +p=13,7 v=-63,-84 +p=100,24 v=-6,-99 +p=1,87 v=-64,-74 +p=52,100 v=15,33 +p=78,24 v=-91,46 +p=86,32 v=-57,97 +p=96,43 v=20,-55 +p=70,67 v=26,-4 +p=86,79 v=-36,57 +p=27,80 v=98,-52 +p=2,1 v=37,81 +p=95,63 v=-81,-2 +p=52,57 v=-60,75 +p=22,6 v=-62,57 +p=82,43 v=94,-99 +p=58,2 v=42,20 +p=74,4 v=-48,-88 +p=14,35 v=-80,-78 +p=61,13 v=-92,-67 +p=18,43 v=17,68 +p=28,28 v=-11,53 +p=55,15 v=84,-53 +p=16,59 v=-74,15 +p=95,80 v=-21,37 +p=68,43 v=10,48 +p=88,93 v=-90,47 +p=54,49 v=10,-60 +p=53,74 v=-27,-38 +p=25,97 v=-53,2 +p=50,0 v=-94,-94 +p=99,33 v=-13,18 +p=66,74 v=-15,-1 +p=28,47 v=13,11 +p=55,64 v=-57,-3 +p=16,43 v=-6,-79 +p=20,12 v=98,-98 +p=24,46 v=42,21 +p=77,40 v=44,79 +p=20,64 v=-96,-86 +p=1,18 v=-30,63 +p=86,83 v=95,81 +p=43,73 v=-30,19 +p=18,79 v=47,75 +p=71,49 v=-37,-26 +p=16,66 v=-71,27 +p=2,101 v=-22,33 +p=13,60 v=-23,-22 +p=79,57 v=-13,38 +p=82,100 v=-88,-98 +p=25,31 v=23,-81 +p=93,63 v=-48,10 +p=44,16 v=-77,8 +p=56,101 v=8,-91 +p=11,29 v=21,-40 +p=65,38 v=-26,-41 +p=70,8 v=69,-5 +p=25,80 v=-87,85 +p=74,55 v=-28,11 +p=96,93 v=-62,21 +p=65,17 v=-75,56 +p=41,99 v=-28,-49 +p=37,90 v=54,-96 +p=30,89 v=-27,-97 +p=95,55 v=20,93 +p=92,64 v=-49,89 +p=25,32 v=-28,63 +p=47,66 v=33,85 +p=96,43 v=-64,-27 +p=78,10 v=93,33 +p=99,67 v=-43,59 +p=38,24 v=99,-16 +p=48,22 v=28,-53 +p=74,18 v=-48,-95 +p=73,6 v=26,-91 +p=77,5 v=-25,98 +p=59,4 v=50,26 +p=91,24 v=-38,-70 +p=4,82 v=-30,20 +p=52,87 v=33,-1 +p=78,8 v=-32,-98 +p=84,50 v=45,66 +p=25,67 v=22,96 +p=77,75 v=85,-8 +p=2,75 v=-95,40 +p=60,8 v=-88,94 +p=78,32 v=39,15 +p=54,89 v=9,-28 +p=100,75 v=-81,13 +p=19,40 v=66,-63 +p=43,25 v=-37,24 +p=16,66 v=-62,-86 +p=94,81 v=-32,78 +p=30,76 v=73,-11 +p=25,65 v=14,-93 +p=69,86 v=-16,-59 +p=43,26 v=-85,-88 +p=54,8 v=-25,32 +p=10,98 v=69,-40 +p=50,78 v=42,3 +p=93,43 v=-44,-85 +p=42,20 v=84,-6 +p=99,14 v=28,26 +p=58,85 v=17,61 +p=1,50 v=89,-79 +p=92,11 v=-39,77 +p=90,62 v=-13,-79 +p=80,55 v=-85,-13 +p=19,4 v=93,18 +p=52,69 v=-68,-52 +p=76,8 v=52,43 +p=83,0 v=-56,55 +p=24,101 v=-55,-57 +p=67,47 v=42,41 +p=83,93 v=36,78 +p=59,65 v=-84,-76 +p=19,24 v=14,-99 +p=19,23 v=-96,-40 +p=29,93 v=53,56 +p=48,19 v=-68,71 +p=95,47 v=7,-34 +p=5,51 v=63,54 +p=61,87 v=-17,30 +p=12,41 v=47,28 +p=79,99 v=86,2 +p=52,37 v=-24,-11 +p=89,66 v=-18,33 +p=60,33 v=-1,-1 +p=4,39 v=46,-61 +p=11,44 v=59,-20 +p=68,15 v=-75,72 +p=51,69 v=-68,-4 +p=95,42 v=-57,24 +p=10,19 v=21,-60 +p=2,30 v=12,80 +p=80,22 v=64,56 +p=73,15 v=-6,56 +p=46,35 v=-69,-41 +p=40,27 v=57,8 +p=88,44 v=53,-68 +p=56,88 v=-68,51 +p=20,12 v=38,67 +p=7,61 v=51,37 +p=13,100 v=53,-95 +p=3,39 v=5,45 +p=18,88 v=29,-25 +p=95,90 v=-72,99 +p=63,86 v=-91,51 +p=47,81 v=63,81 +p=78,77 v=87,-14 +p=59,64 v=-9,48 +p=39,86 v=-93,57 +p=97,46 v=45,45 +p=50,64 v=99,99 +p=15,65 v=-97,-84 +p=22,84 v=57,-61 +p=49,86 v=93,-28 +p=19,76 v=-45,58 +p=57,7 v=25,-29 +p=9,14 v=-80,87 +p=68,59 v=-92,-38 +p=96,30 v=-31,8 +p=16,48 v=72,-34 +p=0,67 v=70,6 +p=33,74 v=-86,-15 +p=46,11 v=-6,40 +p=66,42 v=86,-27 +p=51,53 v=33,86 +p=18,23 v=47,-2 +p=81,91 v=78,-39 +p=57,28 v=-95,-94 +p=75,61 v=10,10 +p=7,34 v=38,-13 +p=93,31 v=19,-95 +p=45,39 v=-51,18 +p=10,13 v=-4,72 +p=21,76 v=-44,-31 +p=81,71 v=3,-48 +p=82,69 v=60,-96 +p=47,11 v=41,-33 +p=72,86 v=94,-25 +p=21,45 v=90,-51 +p=15,19 v=57,-75 +p=52,59 v=8,7 +p=56,24 v=-67,4 +p=17,26 v=71,-47 +p=59,97 v=21,12 +p=74,16 v=-24,77 +p=86,97 v=-32,20 +p=58,96 v=-79,57 +p=91,48 v=-33,-15 +p=44,80 v=-77,6 +p=8,26 v=98,94 +p=8,9 v=-97,-19 +p=70,32 v=-7,1 +p=20,85 v=73,-18 +p=20,94 v=81,26 +p=86,22 v=70,70 +p=53,19 v=92,-40 +p=34,44 v=65,72 +p=94,11 v=-56,36 +p=97,10 v=-47,19 +p=10,101 v=-4,-49 +p=51,66 v=-85,-18 +p=39,17 v=-33,13 +p=98,82 v=-53,16 +p=18,61 v=82,-65 +p=99,100 v=11,40 +p=34,8 v=-85,-50 +p=63,63 v=-50,-62 +p=54,39 v=92,-51 +p=49,77 v=84,88 +p=20,69 v=39,-7 +p=95,65 v=96,-89 +p=42,40 v=-19,16 +p=50,4 v=-14,99 +p=23,47 v=21,-89 +p=64,60 v=-10,-76 +p=53,100 v=84,-70 +p=91,60 v=94,-17 +p=32,36 v=-78,-99 +p=98,68 v=-39,72 +p=69,81 v=-93,-93 +p=70,5 v=-85,35 +p=10,96 v=14,-53 +p=51,32 v=-93,66 +p=52,87 v=-51,6 +p=81,17 v=85,98 +p=5,38 v=-55,-58 +p=72,17 v=18,8 +p=59,81 v=63,-85 +p=66,9 v=-36,-53 +p=15,55 v=-30,83 +p=1,29 v=-39,77 +p=56,85 v=50,-90 +p=50,88 v=-68,57 +p=73,22 v=42,-92 +p=48,39 v=18,43 +p=66,56 v=43,86 +p=23,57 v=73,65 +p=76,87 v=1,85 +p=90,83 v=-40,-11 +p=82,20 v=-54,90 +p=43,95 v=-48,6 +p=46,10 v=24,-74 +p=63,85 v=-43,40 +p=89,101 v=11,81 +p=13,47 v=22,-82 +p=48,92 v=41,-56 +p=100,8 v=-82,90 +p=15,39 v=-3,8 +p=46,66 v=-60,-55 +p=23,91 v=56,2 +p=68,66 v=84,38 +p=10,46 v=-21,-65 +p=62,49 v=25,-75 +p=26,92 v=-70,-62 +p=10,13 v=-29,-2 +p=79,49 v=-57,45 +p=99,12 v=79,29 +p=59,48 v=63,31 +p=15,23 v=8,-67 +p=61,35 v=93,-41 +p=73,11 v=60,43 +p=74,26 v=52,15 +p=5,82 v=-4,-66 +p=46,14 v=-38,76 +p=71,8 v=-48,97 +p=35,9 v=75,-84 +p=91,89 v=28,47 +p=61,84 v=-17,22 +p=38,55 v=48,37 +p=3,68 v=62,69 +p=96,10 v=96,-43 +p=1,67 v=-46,62 +p=65,95 v=-54,-93 +p=57,63 v=42,34 +p=93,11 v=53,-50 +p=38,50 v=40,-65 +p=88,4 v=-48,57 +p=100,30 v=-2,-8 +p=33,19 v=-96,53 +p=42,7 v=32,12 +p=62,7 v=46,58 +p=91,6 v=-73,36 +p=58,41 v=50,76 +p=67,7 v=-25,-95 +p=95,49 v=-38,89 +p=22,93 v=13,54 +p=95,14 v=37,-19 +p=35,25 v=-26,-57 +p=58,97 v=-67,-63 +p=18,28 v=63,75 +p=43,27 v=66,94 +p=95,49 v=-31,42 +p=95,93 v=-89,23 +p=0,35 v=12,56 +p=70,72 v=18,34 +p=100,67 v=19,24 +p=82,18 v=-93,73 +p=50,60 v=67,24 +p=30,28 v=39,-34 +p=2,61 v=12,-35 +p=24,65 v=-20,58 +p=95,27 v=48,-64 +p=92,68 v=-20,60 +p=90,55 v=61,-72 +p=35,80 v=75,-94 +p=30,37 v=-27,-37 +p=0,52 v=87,45 +p=7,60 v=-38,-48 +p=15,7 v=98,4 +p=76,98 v=-1,-16 +p=32,6 v=-1,-29 +p=100,58 v=-47,-77 +p=64,62 v=34,27 +p=13,81 v=46,-14 +p=75,77 v=18,-25 +p=35,44 v=-2,38 +p=30,87 v=-95,33 +p=73,36 v=66,-82 +p=50,85 v=-2,-52 +p=23,43 v=37,74 +p=55,11 v=92,46 +p=44,57 v=48,10 +p=1,9 v=54,46 +p=81,66 v=-15,-35 +p=99,91 v=71,54 +p=5,80 v=-72,20 +p=85,74 v=11,-76 +p=10,61 v=14,48 +p=60,18 v=42,32 +p=21,88 v=4,-29 +p=78,43 v=-67,76 +p=39,69 v=9,-13 +p=89,26 v=-13,-82 +p=27,50 v=-94,65 +p=69,45 v=8,62 +p=32,83 v=40,-1 +p=54,0 v=8,-77 +p=73,21 v=-32,-12 +p=34,39 v=43,29 +p=31,9 v=98,12 +p=11,20 v=73,-88 +p=44,71 v=93,-37 +p=22,20 v=89,-57 +p=95,58 v=37,-86 +p=79,24 v=-30,-46 +p=35,17 v=-78,32 +p=13,90 v=-46,99 +p=55,83 v=8,-52 +p=30,66 v=-54,71 +p=68,70 v=-12,98 +p=43,50 v=48,-93 +p=99,57 v=87,-48 +p=82,83 v=-99,95 +p=35,23 v=-78,-6 +p=0,102 v=-89,-22 +p=39,77 v=-78,-83 +p=50,72 v=-96,-79 +p=20,69 v=-91,-44 +p=9,21 v=46,15 +p=44,90 v=91,33 +p=14,49 v=-7,-10 +p=65,52 v=-16,62 +p=13,0 v=91,83 +p=78,65 v=34,-31 +p=65,92 v=59,95 +p=68,43 v=-32,-55 +p=45,34 v=-94,-30 +p=20,69 v=-8,3 +p=45,67 v=-75,-94 +p=63,14 v=-33,-77 +p=93,48 v=-91,-17 +p=32,85 v=48,82 +p=99,80 v=95,-94 +p=22,25 v=30,-88 +p=68,14 v=50,-15 +p=17,100 v=-63,40 +p=21,53 v=50,23 +p=23,43 v=23,-55 +p=4,76 v=63,58 +p=79,9 v=56,-6 +p=81,95 v=79,85 +p=75,50 v=68,92 +p=40,28 v=-34,-9 +p=51,4 v=49,-7 +p=40,81 v=-32,2 +p=52,14 v=15,-23 +p=94,90 v=-95,24 +p=71,82 v=-24,-42 +p=51,97 v=-43,71 +p=3,79 v=31,87 +p=53,25 v=-27,-75 +p=29,8 v=57,98 +p=74,52 v=-6,58 +p=3,8 v=-48,81 +p=51,95 v=-23,-49 +p=4,22 v=78,-17 +p=85,39 v=36,59 +p=39,8 v=-49,47 +p=5,40 v=-29,-85 +p=75,37 v=-57,-6 +p=8,6 v=-38,-5 +p=3,32 v=96,-92 +p=2,96 v=54,-87 +p=66,75 v=33,-25 +p=81,37 v=41,-24 +p=28,54 v=-72,36 +p=43,65 v=40,-89 +p=51,0 v=-26,40 +p=56,64 v=25,-79 +p=6,38 v=18,60 +p=32,97 v=-79,-88 +p=12,5 v=-79,54 +p=38,72 v=-19,-29 +p=21,51 v=-78,-32 +p=33,27 v=-34,13 +p=71,72 v=-43,-83 +p=68,70 v=-50,51 +p=72,82 v=68,54 +p=64,35 v=-79,21 diff --git a/day14/sample1.in b/day14/sample1.in new file mode 100644 index 0000000..2455da4 --- /dev/null +++ b/day14/sample1.in @@ -0,0 +1,12 @@ +p=0,4 v=3,-3 +p=6,3 v=-1,-3 +p=10,3 v=-1,2 +p=2,0 v=2,-1 +p=0,0 v=1,3 +p=3,0 v=-2,-2 +p=7,6 v=-1,-3 +p=3,0 v=-1,-2 +p=9,3 v=2,3 +p=7,3 v=-1,2 +p=2,4 v=2,-3 +p=9,5 v=-3,-3 diff --git a/day14/sample2.in b/day14/sample2.in new file mode 100644 index 0000000..57cff58 --- /dev/null +++ b/day14/sample2.in @@ -0,0 +1,7 @@ +1.12....... +........... +........... +......11.11 +1.1........ +.........1. +.......1... diff --git a/day14/sample3.in b/day14/sample3.in new file mode 100644 index 0000000..be65cec --- /dev/null +++ b/day14/sample3.in @@ -0,0 +1,53 @@ +Initial state: +........... +........... +........... +........... +..1........ +........... +........... + +After 1 second: +........... +....1...... +........... +........... +........... +........... +........... + +After 2 seconds: +........... +........... +........... +........... +........... +......1.... +........... + +After 3 seconds: +........... +........... +........1.. +........... +........... +........... +........... + +After 4 seconds: +........... +........... +........... +........... +........... +........... +..........1 + +After 5 seconds: +........... +........... +........... +.1......... +........... +........... +........... diff --git a/day14/sample4.in b/day14/sample4.in new file mode 100644 index 0000000..3aa0303 --- /dev/null +++ b/day14/sample4.in @@ -0,0 +1,7 @@ +......2..1. +........... +1.......... +.11........ +.....1..... +...12...... +.1....1.... diff --git a/day14/sample5.in b/day14/sample5.in new file mode 100644 index 0000000..b9485b3 --- /dev/null +++ b/day14/sample5.in @@ -0,0 +1,7 @@ +..... 2..1. +..... ..... +1.... ..... + +..... ..... +...12 ..... +.1... 1.... diff --git a/day14/sol.py b/day14/sol.py new file mode 100644 index 0000000..eb82f0d --- /dev/null +++ b/day14/sol.py @@ -0,0 +1,42 @@ +import re +def parse(file): + robots = [] + for line in file: + match = re.findall(r'-?\d+', line) + px,py, vx,vy = [int(x) for x in match] + robots.append(((px,py),(vx,vy))) + return robots + +def solve(file, W, H): + robots = parse(file) + print(robots) + robots = [iterate(r, 100, W, H) for r in robots] + print(robots) + mx = W//2 + my = H//2 + quads = {1:[], 2:[], 3:[], 4:[]} + print(mx,my) + for (x,y),_ in robots: + q = 0 + if x < mx and y < my: q = 1 + if x > mx and y < my: q = 2 + if x < mx and y > my: q = 3 + if x > mx and y > my: q = 4 + if q > 0: + quads[q].append((x,y)) + print(quads) + + total = 1 + for v in quads.values(): + total *= len(v) + + print(total) + +def iterate(robot, t, W, H): + (px,py), (vx,vy) = robot + px = (px+vx*t)%W + py = (py+vy*t)%H + return (px,py), (vx,vy) + +#solve(open("sample1.in"), 11, 7) +solve(open("input"), 101, 103)