summaryrefslogtreecommitdiff
path: root/2024/day14
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-12-14 12:15:46 +0100
committerBotond Hende <nettingman@gmail.com>2024-12-14 12:15:46 +0100
commit83c2415177293e6b67e7208ca95a2f01e30fb344 (patch)
tree49759621b8c02861ce2bc3dd976bc68854318813 /2024/day14
parent1ffc2556d4ae91a6a568def1fb79410cf70eb795 (diff)
2024 day 14
Diffstat (limited to '2024/day14')
-rw-r--r--2024/day14/input500
-rw-r--r--2024/day14/input_test12
-rw-r--r--2024/day14/solve.py86
3 files changed, 598 insertions, 0 deletions
diff --git a/2024/day14/input b/2024/day14/input
new file mode 100644
index 0000000..5c10a9d
--- /dev/null
+++ b/2024/day14/input
@@ -0,0 +1,500 @@
+p=26,88 v=80,92
+p=2,90 v=77,99
+p=43,54 v=-92,-36
+p=96,14 v=-15,13
+p=33,54 v=97,-64
+p=94,53 v=55,67
+p=45,28 v=79,6
+p=64,90 v=-49,54
+p=71,41 v=-9,67
+p=15,37 v=58,-14
+p=43,53 v=9,8
+p=57,88 v=43,-55
+p=37,96 v=-30,-69
+p=35,54 v=-57,22
+p=56,35 v=23,53
+p=84,66 v=-94,75
+p=15,30 v=-43,21
+p=10,97 v=24,-99
+p=88,63 v=21,-54
+p=77,56 v=47,75
+p=83,30 v=38,-38
+p=95,97 v=-2,-91
+p=7,32 v=-1,-42
+p=62,84 v=-66,69
+p=79,66 v=-48,-34
+p=54,39 v=-12,21
+p=87,9 v=-6,-39
+p=66,101 v=-57,-87
+p=47,83 v=-48,69
+p=48,24 v=2,28
+p=71,48 v=-14,-73
+p=25,36 v=40,-66
+p=10,12 v=-29,5
+p=44,10 v=-79,-17
+p=9,65 v=-7,-65
+p=12,83 v=77,-85
+p=70,38 v=-69,-19
+p=60,38 v=-31,-15
+p=98,20 v=7,-38
+p=38,73 v=-61,33
+p=34,32 v=-21,-96
+p=48,44 v=-19,-34
+p=26,49 v=-50,29
+p=79,84 v=82,-93
+p=50,43 v=41,57
+p=9,76 v=-19,-80
+p=81,20 v=25,36
+p=18,19 v=45,-2
+p=36,85 v=-34,89
+p=38,16 v=63,75
+p=45,31 v=-18,-78
+p=7,42 v=-16,66
+p=55,57 v=-77,-11
+p=30,28 v=-43,-23
+p=57,58 v=43,-49
+p=36,57 v=97,-58
+p=7,47 v=-64,-14
+p=73,33 v=26,-48
+p=52,48 v=7,-48
+p=42,66 v=23,75
+p=77,8 v=-28,-82
+p=52,99 v=44,4
+p=27,15 v=37,-3
+p=72,57 v=65,53
+p=59,85 v=69,-54
+p=58,50 v=57,-95
+p=54,73 v=-66,-19
+p=54,64 v=31,-95
+p=91,33 v=53,-43
+p=67,2 v=-5,34
+p=58,65 v=-31,38
+p=65,93 v=62,17
+p=68,59 v=-44,-42
+p=9,27 v=-60,-99
+p=4,73 v=77,-87
+p=88,60 v=18,-20
+p=82,9 v=-96,-9
+p=99,39 v=-11,-24
+p=23,18 v=-56,28
+p=63,101 v=66,-48
+p=4,63 v=-46,97
+p=41,80 v=31,-49
+p=21,25 v=45,36
+p=89,43 v=-2,63
+p=37,78 v=11,86
+p=37,100 v=32,93
+p=77,33 v=-94,29
+p=25,34 v=-12,-81
+p=31,87 v=-30,70
+p=40,37 v=62,7
+p=16,102 v=-82,4
+p=98,45 v=-8,95
+p=60,23 v=-53,-60
+p=12,83 v=-8,19
+p=49,8 v=-70,-39
+p=38,27 v=25,-49
+p=95,25 v=-59,28
+p=42,56 v=18,-51
+p=5,28 v=24,-73
+p=92,73 v=7,33
+p=41,27 v=88,80
+p=78,16 v=18,3
+p=11,80 v=99,62
+p=100,56 v=46,98
+p=97,47 v=20,8
+p=27,6 v=-78,78
+p=45,12 v=-48,-98
+p=41,29 v=-44,-46
+p=84,69 v=-76,-94
+p=89,4 v=-70,-52
+p=40,62 v=-60,72
+p=62,26 v=40,-48
+p=21,55 v=23,-87
+p=80,45 v=-49,-82
+p=28,100 v=23,49
+p=67,38 v=6,-2
+p=66,40 v=17,-44
+p=72,32 v=-85,-28
+p=53,60 v=35,-14
+p=11,14 v=45,72
+p=86,13 v=-36,49
+p=65,88 v=-58,3
+p=97,79 v=72,17
+p=51,55 v=27,24
+p=2,83 v=33,91
+p=78,76 v=-31,-89
+p=83,12 v=86,49
+p=56,93 v=13,19
+p=20,50 v=-38,45
+p=46,6 v=58,17
+p=48,40 v=66,-8
+p=40,26 v=40,14
+p=71,21 v=92,-59
+p=5,67 v=59,-27
+p=65,53 v=-62,44
+p=14,83 v=69,75
+p=95,35 v=-37,58
+p=36,71 v=-57,-43
+p=68,58 v=-97,37
+p=45,75 v=66,61
+p=25,22 v=-75,-66
+p=38,8 v=-17,-83
+p=32,8 v=-8,71
+p=85,78 v=-44,54
+p=48,64 v=53,-65
+p=97,82 v=77,-78
+p=10,32 v=99,-27
+p=84,39 v=8,-21
+p=83,58 v=74,75
+p=67,65 v=48,-6
+p=78,43 v=25,59
+p=22,83 v=23,19
+p=36,45 v=-65,-95
+p=95,51 v=-32,-59
+p=66,5 v=74,78
+p=76,27 v=-42,52
+p=99,64 v=75,-46
+p=51,102 v=44,-25
+p=97,14 v=-41,78
+p=78,56 v=-76,1
+p=77,12 v=-1,-97
+p=58,1 v=13,34
+p=5,28 v=68,-8
+p=30,6 v=31,-83
+p=11,91 v=78,-82
+p=15,39 v=78,-26
+p=32,58 v=84,-36
+p=16,55 v=-36,75
+p=100,96 v=16,42
+p=89,28 v=-6,87
+p=48,19 v=-57,21
+p=42,50 v=-31,15
+p=54,11 v=92,-24
+p=77,98 v=-9,-33
+p=71,36 v=2,60
+p=18,44 v=-55,-66
+p=26,16 v=-62,79
+p=35,80 v=93,-41
+p=90,30 v=29,-96
+p=44,59 v=-26,-4
+p=87,52 v=-43,89
+p=91,39 v=3,-52
+p=35,52 v=49,8
+p=27,60 v=-12,-35
+p=7,18 v=-53,-14
+p=65,67 v=-32,91
+p=13,6 v=19,93
+p=94,28 v=35,33
+p=22,29 v=-38,-78
+p=91,59 v=26,-39
+p=84,43 v=-76,67
+p=29,102 v=-8,-99
+p=84,92 v=-46,-36
+p=56,10 v=-88,20
+p=88,81 v=16,63
+p=19,20 v=-41,79
+p=43,54 v=48,59
+p=11,0 v=28,-61
+p=4,40 v=-94,-82
+p=38,101 v=-18,55
+p=88,18 v=-2,8
+p=13,19 v=28,21
+p=29,11 v=6,-69
+p=76,91 v=16,49
+p=74,29 v=78,74
+p=45,53 v=58,-80
+p=86,11 v=94,1
+p=65,59 v=-14,-6
+p=60,62 v=98,64
+p=57,3 v=48,-32
+p=46,48 v=83,15
+p=54,78 v=58,-63
+p=91,35 v=-19,-74
+p=36,83 v=55,-11
+p=67,53 v=63,-20
+p=20,86 v=-25,63
+p=37,7 v=-30,79
+p=42,7 v=75,-54
+p=76,73 v=14,1
+p=34,57 v=1,-21
+p=31,76 v=79,-44
+p=53,93 v=26,35
+p=60,65 v=-97,-42
+p=99,102 v=-46,-55
+p=65,1 v=-32,-25
+p=86,14 v=60,-61
+p=9,95 v=85,-39
+p=63,86 v=-95,95
+p=4,93 v=94,92
+p=7,81 v=99,-40
+p=28,0 v=28,5
+p=52,41 v=-2,7
+p=14,64 v=-16,-57
+p=22,78 v=-56,54
+p=44,98 v=-88,45
+p=52,72 v=22,-79
+p=63,35 v=13,-52
+p=62,64 v=-62,39
+p=10,53 v=67,31
+p=16,100 v=-69,-63
+p=17,47 v=92,-56
+p=86,22 v=69,94
+p=49,37 v=-79,95
+p=92,96 v=-50,48
+p=54,5 v=-48,70
+p=67,12 v=-76,34
+p=10,10 v=73,34
+p=100,4 v=6,72
+p=1,32 v=-90,37
+p=33,22 v=-8,14
+p=10,96 v=94,-9
+p=84,95 v=-19,-25
+p=42,27 v=66,-60
+p=67,91 v=-76,11
+p=21,23 v=-95,50
+p=53,24 v=-57,-97
+p=19,1 v=47,-62
+p=84,59 v=-5,-2
+p=10,35 v=37,-88
+p=56,76 v=-92,-33
+p=92,83 v=16,62
+p=6,97 v=72,11
+p=65,29 v=4,-82
+p=37,52 v=4,29
+p=78,53 v=39,74
+p=100,50 v=83,-3
+p=43,48 v=-61,8
+p=78,102 v=-22,-99
+p=89,73 v=25,2
+p=91,86 v=7,48
+p=88,37 v=-45,20
+p=80,91 v=81,32
+p=6,6 v=24,-83
+p=86,57 v=3,-14
+p=16,12 v=32,-76
+p=46,53 v=-67,47
+p=79,11 v=-54,64
+p=87,99 v=-35,-7
+p=8,34 v=-37,-75
+p=73,61 v=-70,13
+p=38,2 v=-84,40
+p=92,23 v=9,25
+p=35,60 v=-25,31
+p=72,9 v=16,27
+p=9,33 v=-7,-31
+p=98,17 v=50,28
+p=62,15 v=34,-54
+p=72,4 v=21,86
+p=46,53 v=-39,61
+p=80,58 v=84,-86
+p=83,88 v=-86,29
+p=2,38 v=62,-38
+p=70,61 v=23,-97
+p=100,77 v=-64,-72
+p=27,45 v=58,-14
+p=25,3 v=40,72
+p=73,102 v=-74,34
+p=80,63 v=-58,-56
+p=50,52 v=53,-7
+p=33,82 v=19,99
+p=28,15 v=-52,57
+p=66,43 v=-54,-6
+p=44,40 v=-56,63
+p=31,12 v=36,65
+p=3,41 v=-99,52
+p=35,87 v=-4,-86
+p=79,84 v=-67,99
+p=88,22 v=16,-2
+p=71,85 v=92,70
+p=96,60 v=76,98
+p=38,48 v=14,-7
+p=86,15 v=-33,-75
+p=75,57 v=66,-85
+p=85,68 v=-19,-27
+p=46,95 v=75,48
+p=14,71 v=32,1
+p=74,71 v=-54,-95
+p=11,12 v=-64,13
+p=17,37 v=81,53
+p=2,15 v=23,-3
+p=9,75 v=-39,47
+p=46,70 v=44,-34
+p=86,48 v=-15,-98
+p=32,45 v=62,81
+p=22,3 v=59,94
+p=24,81 v=-82,25
+p=85,11 v=-3,-32
+p=96,86 v=20,39
+p=43,2 v=62,42
+p=45,98 v=-26,-54
+p=51,16 v=92,-53
+p=77,13 v=-45,-61
+p=58,54 v=-44,30
+p=52,3 v=-49,-33
+p=28,76 v=-12,-64
+p=45,38 v=-53,34
+p=11,28 v=85,-67
+p=29,88 v=90,4
+p=44,102 v=-21,17
+p=15,37 v=94,66
+p=73,32 v=30,80
+p=65,86 v=-19,-21
+p=34,64 v=-26,16
+p=60,2 v=-18,78
+p=39,0 v=-34,94
+p=28,15 v=32,-93
+p=8,100 v=98,40
+p=62,62 v=48,60
+p=37,44 v=25,10
+p=39,72 v=-96,91
+p=84,33 v=93,18
+p=81,44 v=69,52
+p=37,22 v=89,-48
+p=0,42 v=-63,-36
+p=35,42 v=-17,-22
+p=90,39 v=-76,-30
+p=55,74 v=-22,-92
+p=1,55 v=-64,-86
+p=60,23 v=-9,-97
+p=21,4 v=-91,64
+p=90,72 v=56,95
+p=35,41 v=58,22
+p=57,81 v=-9,-96
+p=11,102 v=-73,-17
+p=45,58 v=-43,52
+p=43,25 v=48,-37
+p=78,12 v=12,42
+p=48,43 v=79,-29
+p=31,100 v=-30,-54
+p=24,63 v=-61,28
+p=44,67 v=-35,-94
+p=100,49 v=-98,-52
+p=29,54 v=41,-64
+p=29,33 v=50,44
+p=22,40 v=-47,8
+p=56,67 v=-5,75
+p=78,95 v=78,-48
+p=58,72 v=-48,-65
+p=6,94 v=90,9
+p=76,58 v=12,-80
+p=68,62 v=-58,61
+p=62,85 v=57,91
+p=16,88 v=94,-5
+p=72,0 v=-74,-91
+p=0,75 v=11,-93
+p=48,42 v=92,-6
+p=24,102 v=68,-78
+p=21,86 v=-56,25
+p=3,63 v=-11,-43
+p=36,102 v=14,-4
+p=56,52 v=4,-58
+p=5,55 v=-1,84
+p=92,1 v=-94,-84
+p=27,50 v=54,-88
+p=80,91 v=-76,33
+p=50,19 v=9,87
+p=69,37 v=-58,-8
+p=34,63 v=14,61
+p=17,52 v=19,37
+p=93,65 v=-15,46
+p=37,15 v=-13,56
+p=100,63 v=-68,17
+p=41,81 v=97,-92
+p=62,17 v=-72,13
+p=0,16 v=-77,-31
+p=14,17 v=41,28
+p=27,34 v=58,-74
+p=35,40 v=14,21
+p=8,88 v=-24,98
+p=35,28 v=-94,46
+p=93,42 v=-59,22
+p=83,26 v=-11,1
+p=2,22 v=-42,65
+p=35,102 v=-25,-4
+p=21,22 v=41,-81
+p=35,0 v=5,41
+p=70,99 v=74,34
+p=75,28 v=4,81
+p=11,91 v=-56,33
+p=16,52 v=65,-38
+p=55,14 v=-66,78
+p=39,68 v=-71,7
+p=25,53 v=-56,-29
+p=70,42 v=-33,-35
+p=40,81 v=-70,47
+p=15,78 v=-82,26
+p=85,97 v=51,-33
+p=78,72 v=43,-48
+p=92,60 v=-77,10
+p=55,65 v=-14,-79
+p=46,45 v=92,-72
+p=15,54 v=-3,-51
+p=65,2 v=-80,-70
+p=73,30 v=78,-74
+p=23,12 v=-64,-98
+p=85,3 v=-68,-11
+p=30,69 v=-21,69
+p=57,38 v=-18,37
+p=11,88 v=-82,-19
+p=55,101 v=-54,44
+p=68,56 v=57,-65
+p=4,81 v=-12,92
+p=43,70 v=62,-27
+p=42,25 v=-31,13
+p=0,61 v=-16,-64
+p=45,25 v=31,-82
+p=23,75 v=-47,92
+p=57,33 v=-30,25
+p=0,34 v=-94,-36
+p=78,57 v=34,-43
+p=67,99 v=-22,4
+p=3,46 v=-99,8
+p=44,28 v=80,-66
+p=84,60 v=72,18
+p=51,66 v=-88,67
+p=38,7 v=-61,-47
+p=34,23 v=40,-88
+p=66,46 v=83,-81
+p=73,98 v=51,33
+p=37,56 v=62,81
+p=30,98 v=28,58
+p=71,99 v=38,62
+p=64,7 v=52,86
+p=26,53 v=-12,89
+p=87,50 v=43,-29
+p=65,101 v=87,-96
+p=34,52 v=-21,66
+p=14,84 v=-60,3
+p=4,7 v=-50,49
+p=45,73 v=-17,-64
+p=18,92 v=-29,40
+p=83,54 v=2,-64
+p=95,26 v=60,50
+p=86,80 v=95,25
+p=5,52 v=-25,15
+p=99,98 v=-46,77
+p=81,52 v=25,9
+p=53,89 v=-54,-83
+p=60,36 v=92,73
+p=78,27 v=7,15
+p=55,51 v=-63,-74
+p=5,85 v=-56,-97
+p=26,17 v=6,46
+p=37,36 v=-67,51
+p=69,52 v=96,67
+p=24,86 v=-11,35
+p=44,1 v=-21,26
+p=55,95 v=61,-33
+p=75,101 v=65,-3
+p=16,17 v=-29,29
+p=80,69 v=12,68
+p=78,61 v=-11,-7
+p=99,99 v=11,-62
+p=41,47 v=47,-86
+p=52,81 v=31,54
+p=86,60 v=-37,16
+p=15,89 v=-43,-18
+p=72,99 v=12,26
+p=42,15 v=-13,-47
+p=37,79 v=-41,70 \ No newline at end of file
diff --git a/2024/day14/input_test b/2024/day14/input_test
new file mode 100644
index 0000000..72a324a
--- /dev/null
+++ b/2024/day14/input_test
@@ -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 \ No newline at end of file
diff --git a/2024/day14/solve.py b/2024/day14/solve.py
new file mode 100644
index 0000000..acbd6af
--- /dev/null
+++ b/2024/day14/solve.py
@@ -0,0 +1,86 @@
+input_file = "input"
+
+def print_positions(robots, col_count, row_count, iter_count):
+ print_data = {}
+ for robot in robots:
+ key = (robot[1], robot[0])
+ if key not in print_data:
+ print_data[key] = 0
+
+ print_data[key] += 1
+
+ longest_line_threshold = 10
+ longest_line = 0
+ print_this = False
+ for row in range(row_count):
+ for col in range(col_count):
+ key = (row, col)
+ if key in print_data:
+ longest_line += 1
+ if longest_line >= longest_line_threshold:
+ print_this = True
+ break
+ else:
+ longest_line = 0
+
+ if print_this:
+ break
+
+ if print_this:
+ print(f"Positions after {iter_count + 1:000} seconds")
+ for row in range(row_count):
+ for col in range(col_count):
+ key = (row, col)
+ if key in print_data:
+ print(print_data[key], end="")
+ else:
+ print(".", end="")
+ print()
+
+ input()
+
+
+def move_robots(robots: list[list[int]], col_count: int, row_count: int):
+ for robot in robots:
+ robot[0] += robot[2]
+ robot[1] += robot[3]
+
+ if robot[0] < 0:
+ robot[0] += col_count
+ elif robot[0] >= col_count:
+ robot[0] -= col_count
+
+ if robot[1] < 0:
+ robot[1] += row_count
+ elif robot[1] >= row_count:
+ robot[1] -= row_count
+
+data: list[list[int]] = []
+with open(input_file) as f:
+ for line in f:
+ data.append([int(elem) for elem in line.strip().replace("p=", "").replace(" v=", ",").split(",")])
+
+wideness = 101 if input_file == "input" else 11
+height = 103 if input_file == "input" else 7
+
+print_mode_on = True
+# second part
+
+range_max = 100 if not print_mode_on else 10000
+for ii in range(range_max):
+ move_robots(data, wideness, height)
+ if print_mode_on:
+ print_positions(data, wideness, height, ii)
+
+middle_col = wideness // 2
+middle_row = height // 2
+
+quads = [[0, 0], [0, 0]]
+for elem in data:
+ if elem[0] == middle_col or elem[1] == middle_row:
+ continue
+
+ quads[0 if elem[0] < middle_col else 1][0 if elem[1] < middle_row else 1] += 1
+
+result = quads[0][0] * quads[1][1] * quads[0][1] * quads[1][0]
+print(result)