- commit
- 0e4eb86b03c05b4ec8569d78acfeb5d36dda14b3
- parent
- 92319530e73d7c740d1673378d919d252205af84
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-12-14 06:59
2024-12-14
Diffstat
A | 2024/14/input.txt | 500 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | 2024/14/solution.rs | 83 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | 2024/14/test.txt | 12 | ++++++++++++ |
3 files changed, 595 insertions, 0 deletions
diff --git a/2024/14/input.txt b/2024/14/input.txt
@@ -0,0 +1,500 @@ -1 1 p=69,95 v=70,-27 -1 2 p=95,51 v=-76,-2 -1 3 p=54,32 v=-80,-4 -1 4 p=41,28 v=27,6 -1 5 p=63,6 v=-33,55 -1 6 p=80,2 v=77,-78 -1 7 p=69,53 v=54,-1 -1 8 p=78,40 v=-11,99 -1 9 p=36,55 v=-18,9 -1 10 p=71,24 v=83,67 -1 11 p=3,77 v=-38,71 -1 12 p=13,54 v=5,-73 -1 13 p=89,20 v=-9,25 -1 14 p=39,70 v=-40,-61 -1 15 p=38,55 v=-27,30 -1 16 p=40,4 v=-87,19 -1 17 p=62,23 v=35,-48 -1 18 p=65,46 v=-61,13 -1 19 p=43,58 v=-93,2 -1 20 p=1,19 v=-61,17 -1 21 p=81,23 v=-51,53 -1 22 p=11,53 v=78,20 -1 23 p=70,67 v=-70,-67 -1 24 p=20,45 v=-88,40 -1 25 p=90,37 v=-37,-8 -1 26 p=90,0 v=-11,51 -1 27 p=50,89 v=-20,80 -1 28 p=84,58 v=29,48 -1 29 p=1,24 v=-76,-50 -1 30 p=39,70 v=-16,-67 -1 31 p=4,58 v=91,-97 -1 32 p=35,3 v=54,-86 -1 33 p=55,38 v=56,-14 -1 34 p=81,6 v=-4,-84 -1 35 p=90,42 v=17,-30 -1 36 p=54,0 v=8,13 -1 37 p=30,30 v=88,-42 -1 38 p=3,84 v=-29,-17 -1 39 p=75,6 v=-28,-88 -1 40 p=63,6 v=-94,-98 -1 41 p=58,19 v=-93,75 -1 42 p=97,63 v=-3,51 -1 43 p=6,99 v=-30,50 -1 44 p=48,83 v=-32,88 -1 45 p=59,40 v=-59,-73 -1 46 p=54,102 v=-86,13 -1 47 p=93,48 v=-91,-18 -1 48 p=80,4 v=72,-32 -1 49 p=89,11 v=98,-56 -1 50 p=64,93 v=-72,-5 -1 51 p=0,36 v=31,6 -1 52 p=46,56 v=-88,-91 -1 53 p=58,94 v=-67,1 -1 54 p=80,73 v=-18,96 -1 55 p=3,101 v=-2,-21 -1 56 p=67,30 v=-45,87 -1 57 p=97,77 v=-3,74 -1 58 p=24,54 v=66,-89 -1 59 p=96,17 v=99,-71 -1 60 p=84,7 v=50,-20 -1 61 p=89,62 v=65,-67 -1 62 p=13,12 v=-48,-90 -1 63 p=73,2 v=-45,39 -1 64 p=47,100 v=-59,90 -1 65 p=36,9 v=46,-76 -1 66 p=78,52 v=12,-70 -1 67 p=1,42 v=-91,18 -1 68 p=20,23 v=-89,61 -1 69 p=96,47 v=24,-79 -1 70 p=98,100 v=31,27 -1 71 p=35,73 v=-80,-29 -1 72 p=40,39 v=81,10 -1 73 p=8,7 v=25,21 -1 74 p=23,10 v=-1,19 -1 75 p=95,77 v=-27,49 -1 76 p=43,88 v=20,-80 -1 77 p=58,83 v=21,-35 -1 78 p=0,26 v=38,-20 -1 79 p=47,92 v=61,94 -1 80 p=23,74 v=72,-22 -1 81 p=52,54 v=1,-93 -1 82 p=8,61 v=65,-59 -1 83 p=8,52 v=72,-93 -1 84 p=63,14 v=17,60 -1 85 p=16,51 v=82,-9 -1 86 p=77,34 v=56,-20 -1 87 p=74,5 v=-58,-72 -1 88 p=35,77 v=6,58 -1 89 p=37,79 v=-81,-9 -1 90 p=25,78 v=26,94 -1 91 p=40,48 v=40,17 -1 92 p=62,73 v=-45,23 -1 93 p=47,72 v=42,84 -1 94 p=83,12 v=37,-90 -1 95 p=65,2 v=-65,65 -1 96 p=29,52 v=67,-77 -1 97 p=98,39 v=24,4 -1 98 p=76,66 v=83,40 -1 99 p=6,26 v=18,-16 -1 100 p=68,89 v=-52,-3 -1 101 p=64,19 v=30,-63 -1 102 p=36,39 v=-68,-10 -1 103 p=46,30 v=-53,-22 -1 104 p=77,44 v=-45,-4 -1 105 p=82,60 v=78,8 -1 106 p=87,77 v=-37,84 -1 107 p=93,58 v=-57,-89 -1 108 p=55,44 v=55,8 -1 109 p=1,60 v=-16,-81 -1 110 p=98,62 v=-30,-93 -1 111 p=64,74 v=-25,56 -1 112 p=64,22 v=3,29 -1 113 p=94,32 v=-57,-34 -1 114 p=35,88 v=-94,-19 -1 115 p=53,87 v=89,-78 -1 116 p=18,33 v=-33,-96 -1 117 p=62,30 v=-39,1 -1 118 p=3,79 v=-47,-24 -1 119 p=32,102 v=41,98 -1 120 p=63,85 v=-76,86 -1 121 p=55,28 v=-64,-26 -1 122 p=29,93 v=72,-87 -1 123 p=96,41 v=-50,-20 -1 124 p=38,21 v=-7,95 -1 125 p=67,20 v=-97,-54 -1 126 p=12,26 v=-26,32 -1 127 p=21,35 v=-68,77 -1 128 p=38,49 v=80,64 -1 129 p=94,55 v=57,-72 -1 130 p=60,65 v=90,60 -1 131 p=73,85 v=-75,-73 -1 132 p=83,42 v=83,42 -1 133 p=6,19 v=-89,-25 -1 134 p=72,68 v=63,-17 -1 135 p=15,31 v=86,83 -1 136 p=39,31 v=74,81 -1 137 p=42,12 v=-98,-25 -1 138 p=64,28 v=81,-31 -1 139 p=38,98 v=-35,-99 -1 140 p=1,67 v=85,-59 -1 141 p=44,7 v=-65,-58 -1 142 p=75,41 v=-64,70 -1 143 p=67,90 v=-37,-15 -1 144 p=56,20 v=-93,-44 -1 145 p=70,101 v=-58,-15 -1 146 p=69,8 v=90,-34 -1 147 p=56,86 v=42,74 -1 148 p=74,1 v=-85,-66 -1 149 p=55,16 v=48,53 -1 150 p=98,85 v=10,-86 -1 151 p=83,15 v=-84,-64 -1 152 p=34,33 v=98,-37 -1 153 p=30,59 v=88,52 -1 154 p=55,49 v=55,34 -1 155 p=97,39 v=-30,-36 -1 156 p=31,102 v=13,-80 -1 157 p=42,98 v=-33,-3 -1 158 p=27,71 v=-70,-10 -1 159 p=30,79 v=-82,44 -1 160 p=34,88 v=-8,-29 -1 161 p=0,55 v=51,-79 -1 162 p=26,12 v=19,-72 -1 163 p=3,71 v=-36,80 -1 164 p=50,59 v=22,-93 -1 165 p=74,44 v=-79,95 -1 166 p=16,5 v=-8,29 -1 167 p=99,11 v=30,47 -1 168 p=73,43 v=89,-28 -1 169 p=26,4 v=53,27 -1 170 p=11,21 v=-22,-28 -1 171 p=14,3 v=60,15 -1 172 p=26,1 v=-37,48 -1 173 p=6,62 v=-86,75 -1 174 p=24,87 v=90,17 -1 175 p=47,90 v=81,-11 -1 176 p=90,65 v=98,-71 -1 177 p=91,59 v=-4,-35 -1 178 p=9,29 v=97,82 -1 179 p=89,15 v=30,51 -1 180 p=50,100 v=20,-78 -1 181 p=62,36 v=-96,78 -1 182 p=9,102 v=99,29 -1 183 p=80,97 v=27,55 -1 184 p=36,13 v=74,-64 -1 185 p=88,20 v=36,35 -1 186 p=25,3 v=87,-90 -1 187 p=11,31 v=-83,-36 -1 188 p=67,51 v=-34,32 -1 189 p=38,66 v=-34,-67 -1 190 p=30,11 v=-39,50 -1 191 p=3,86 v=95,-29 -1 192 p=76,4 v=63,-64 -1 193 p=28,99 v=-89,56 -1 194 p=30,97 v=-48,3 -1 195 p=98,33 v=84,-48 -1 196 p=82,26 v=-64,69 -1 197 p=98,73 v=-3,-33 -1 198 p=16,81 v=-67,2 -1 199 p=21,96 v=92,-37 -1 200 p=44,36 v=-41,-87 -1 201 p=48,44 v=-32,77 -1 202 p=79,61 v=-90,19 -1 203 p=26,46 v=66,81 -1 204 p=11,69 v=25,-59 -1 205 p=13,75 v=12,-47 -1 206 p=79,83 v=63,-31 -1 207 p=40,82 v=-1,-3 -1 208 p=89,85 v=91,78 -1 209 p=27,28 v=-83,-17 -1 210 p=35,10 v=-82,73 -1 211 p=23,84 v=33,-11 -1 212 p=9,2 v=99,21 -1 213 p=39,86 v=5,-67 -1 214 p=45,39 v=87,-28 -1 215 p=80,44 v=-70,32 -1 216 p=14,59 v=-73,71 -1 217 p=51,99 v=-10,61 -1 218 p=99,51 v=-16,22 -1 219 p=2,17 v=-63,77 -1 220 p=45,31 v=-73,69 -1 221 p=77,7 v=63,-72 -1 222 p=31,74 v=-29,43 -1 223 p=100,77 v=-2,93 -1 224 p=23,38 v=53,65 -1 225 p=92,89 v=-94,-23 -1 226 p=71,12 v=-20,55 -1 227 p=92,1 v=-44,-48 -1 228 p=61,62 v=17,74 -1 229 p=44,2 v=-1,-51 -1 230 p=27,82 v=6,78 -1 231 p=89,19 v=-44,-42 -1 232 p=96,14 v=31,45 -1 233 p=32,31 v=53,67 -1 234 p=26,89 v=79,-21 -1 235 p=96,24 v=-51,59 -1 236 p=2,30 v=-66,72 -1 237 p=70,91 v=55,15 -1 238 p=87,1 v=37,29 -1 239 p=76,80 v=-11,46 -1 240 p=73,1 v=-72,-72 -1 241 p=100,43 v=65,10 -1 242 p=62,32 v=-12,79 -1 243 p=33,29 v=74,-22 -1 244 p=76,24 v=-6,-31 -1 245 p=3,71 v=-96,-50 -1 246 p=18,100 v=46,86 -1 247 p=36,101 v=73,-15 -1 248 p=81,76 v=-50,68 -1 249 p=35,25 v=81,-44 -1 250 p=74,79 v=16,74 -1 251 p=7,53 v=65,-81 -1 252 p=89,96 v=30,-9 -1 253 p=20,2 v=-82,-7 -1 254 p=47,97 v=-13,5 -1 255 p=50,16 v=96,-94 -1 256 p=19,45 v=-89,-4 -1 257 p=45,2 v=89,-64 -1 258 p=60,35 v=90,73 -1 259 p=47,45 v=42,95 -1 260 p=55,24 v=-32,31 -1 261 p=15,74 v=-96,34 -1 262 p=69,86 v=36,83 -1 263 p=69,94 v=76,98 -1 264 p=33,92 v=-4,-63 -1 265 p=52,5 v=28,-56 -1 266 p=14,58 v=91,-30 -1 267 p=9,30 v=26,-20 -1 268 p=9,14 v=19,-8 -1 269 p=17,69 v=12,46 -1 270 p=89,33 v=-68,-34 -1 271 p=7,88 v=59,-66 -1 272 p=79,93 v=-5,72 -1 273 p=43,95 v=27,-9 -1 274 p=43,62 v=41,10 -1 275 p=60,0 v=-52,-84 -1 276 p=7,25 v=71,-38 -1 277 p=76,13 v=-51,-24 -1 278 p=11,5 v=-89,-76 -1 279 p=69,58 v=-92,-55 -1 280 p=36,87 v=34,80 -1 281 p=57,76 v=-32,-29 -1 282 p=78,25 v=-34,27 -1 283 p=58,60 v=-39,-65 -1 284 p=13,9 v=33,-36 -1 285 p=38,5 v=-23,45 -1 286 p=99,49 v=93,-57 -1 287 p=18,11 v=-89,57 -1 288 p=74,36 v=-37,-73 -1 289 p=70,1 v=57,-60 -1 290 p=80,65 v=-11,46 -1 291 p=41,16 v=28,-18 -1 292 p=35,23 v=-80,-18 -1 293 p=82,11 v=76,67 -1 294 p=74,47 v=25,-81 -1 295 p=12,98 v=66,5 -1 296 p=69,23 v=-92,-52 -1 297 p=2,85 v=58,92 -1 298 p=17,68 v=-48,-63 -1 299 p=22,60 v=-12,89 -1 300 p=75,34 v=-11,73 -1 301 p=16,27 v=87,-99 -1 302 p=95,34 v=-3,-20 -1 303 p=16,20 v=38,-10 -1 304 p=10,22 v=-22,-58 -1 305 p=53,7 v=75,43 -1 306 p=74,27 v=63,63 -1 307 p=2,84 v=-27,-71 -1 308 p=99,33 v=61,90 -1 309 p=89,7 v=17,53 -1 310 p=65,2 v=49,41 -1 311 p=83,48 v=-78,-99 -1 312 p=34,27 v=52,-72 -1 313 p=46,24 v=-33,63 -1 314 p=48,64 v=-60,28 -1 315 p=46,16 v=21,-60 -1 316 p=88,23 v=38,-40 -1 317 p=77,72 v=63,46 -1 318 p=33,57 v=-21,28 -1 319 p=36,82 v=11,64 -1 320 p=83,38 v=17,91 -1 321 p=49,67 v=94,52 -1 322 p=95,38 v=23,-36 -1 323 p=87,29 v=50,75 -1 324 p=88,70 v=-64,50 -1 325 p=56,18 v=22,-14 -1 326 p=85,7 v=24,3 -1 327 p=69,39 v=56,6 -1 328 p=82,97 v=77,41 -1 329 p=28,3 v=-88,29 -1 330 p=59,15 v=-86,-48 -1 331 p=43,78 v=64,84 -1 332 p=78,86 v=-55,-3 -1 333 p=62,38 v=-79,-2 -1 334 p=81,68 v=94,46 -1 335 p=48,80 v=-85,-67 -1 336 p=13,77 v=-90,32 -1 337 p=51,43 v=49,30 -1 338 p=94,55 v=-57,30 -1 339 p=41,15 v=-13,-38 -1 340 p=40,97 v=-53,80 -1 341 p=39,6 v=34,-38 -1 342 p=97,96 v=77,27 -1 343 p=73,87 v=76,-21 -1 344 p=27,22 v=76,-17 -1 345 p=80,94 v=94,-7 -1 346 p=78,18 v=-31,-64 -1 347 p=34,47 v=81,-95 -1 348 p=87,96 v=51,94 -1 349 p=35,21 v=-14,-48 -1 350 p=95,16 v=-85,-53 -1 351 p=77,14 v=-90,59 -1 352 p=49,48 v=41,14 -1 353 p=75,52 v=-92,32 -1 354 p=16,91 v=96,-11 -1 355 p=50,24 v=-46,92 -1 356 p=88,38 v=37,-93 -1 357 p=97,13 v=85,43 -1 358 p=81,44 v=50,99 -1 359 p=97,45 v=-97,-75 -1 360 p=35,91 v=94,15 -1 361 p=3,74 v=18,-47 -1 362 p=64,32 v=62,91 -1 363 p=74,16 v=31,-64 -1 364 p=65,37 v=44,89 -1 365 p=90,25 v=-98,-64 -1 366 p=13,98 v=-36,-5 -1 367 p=83,102 v=84,-90 -1 368 p=42,15 v=-67,45 -1 369 p=8,10 v=86,73 -1 370 p=72,84 v=-11,-9 -1 371 p=58,99 v=36,-84 -1 372 p=59,19 v=-5,51 -1 373 p=22,38 v=-76,-78 -1 374 p=24,8 v=-68,45 -1 375 p=60,70 v=-32,44 -1 376 p=41,5 v=-19,-40 -1 377 p=28,4 v=-48,35 -1 378 p=53,47 v=-38,72 -1 379 p=82,80 v=23,84 -1 380 p=21,95 v=19,-17 -1 381 p=85,5 v=-71,-86 -1 382 p=90,2 v=-44,-46 -1 383 p=92,63 v=-84,-53 -1 384 p=82,67 v=83,-83 -1 385 p=9,76 v=-29,-65 -1 386 p=87,55 v=-90,-75 -1 387 p=2,59 v=-19,33 -1 388 p=17,78 v=38,-17 -1 389 p=99,8 v=51,37 -1 390 p=58,35 v=42,79 -1 391 p=9,97 v=-77,37 -1 392 p=63,19 v=-32,-36 -1 393 p=76,31 v=50,81 -1 394 p=14,68 v=-89,42 -1 395 p=49,45 v=97,7 -1 396 p=81,52 v=-38,-93 -1 397 p=75,97 v=3,80 -1 398 p=48,101 v=67,-78 -1 399 p=89,95 v=91,-7 -1 400 p=6,96 v=52,-1 -1 401 p=67,37 v=75,79 -1 402 p=73,47 v=37,2 -1 403 p=7,98 v=32,3 -1 404 p=7,87 v=-43,-23 -1 405 p=27,61 v=62,-79 -1 406 p=30,85 v=6,1 -1 407 p=42,29 v=34,-46 -1 408 p=47,30 v=95,73 -1 409 p=25,88 v=6,78 -1 410 p=72,92 v=36,84 -1 411 p=90,92 v=64,31 -1 412 p=79,70 v=-72,90 -1 413 p=39,77 v=81,-38 -1 414 p=50,2 v=-88,-35 -1 415 p=90,91 v=38,-35 -1 416 p=75,17 v=89,61 -1 417 p=98,60 v=-16,-49 -1 418 p=56,1 v=56,84 -1 419 p=1,82 v=55,-45 -1 420 p=22,59 v=86,-81 -1 421 p=100,84 v=-23,-88 -1 422 p=90,51 v=-17,-91 -1 423 p=82,53 v=3,-77 -1 424 p=77,96 v=36,-9 -1 425 p=76,52 v=-38,-69 -1 426 p=8,18 v=-72,-72 -1 427 p=48,74 v=-20,8 -1 428 p=22,81 v=90,-2 -1 429 p=55,102 v=-73,52 -1 430 p=83,79 v=-48,14 -1 431 p=83,13 v=97,-60 -1 432 p=35,96 v=-94,-9 -1 433 p=49,56 v=-45,89 -1 434 p=55,16 v=-10,71 -1 435 p=58,51 v=89,16 -1 436 p=1,15 v=-37,83 -1 437 p=27,66 v=-41,-67 -1 438 p=68,92 v=56,7 -1 439 p=48,41 v=35,47 -1 440 p=69,38 v=56,53 -1 441 p=57,87 v=-58,-42 -1 442 p=69,50 v=69,50 -1 443 p=11,101 v=72,7 -1 444 p=61,5 v=-20,-8 -1 445 p=41,22 v=-53,-54 -1 446 p=2,40 v=45,-8 -1 447 p=15,44 v=-21,67 -1 448 p=25,44 v=80,-79 -1 449 p=23,91 v=-25,-79 -1 450 p=82,55 v=-90,-85 -1 451 p=37,13 v=-26,-26 -1 452 p=10,2 v=-90,96 -1 453 p=10,45 v=-95,90 -1 454 p=61,12 v=55,-60 -1 455 p=97,37 v=98,89 -1 456 p=7,95 v=-2,-90 -1 457 p=23,93 v=39,5 -1 458 p=70,74 v=12,44 -1 459 p=28,54 v=-41,-98 -1 460 p=34,91 v=25,-84 -1 461 p=16,48 v=-21,-57 -1 462 p=87,83 v=17,-21 -1 463 p=82,64 v=23,36 -1 464 p=60,75 v=42,-29 -1 465 p=30,16 v=23,64 -1 466 p=4,80 v=92,92 -1 467 p=74,26 v=62,65 -1 468 p=24,11 v=25,-58 -1 469 p=26,97 v=57,20 -1 470 p=2,99 v=-62,21 -1 471 p=44,62 v=61,48 -1 472 p=8,43 v=79,-89 -1 473 p=32,93 v=-54,37 -1 474 p=31,33 v=6,-12 -1 475 p=80,35 v=-51,-16 -1 476 p=72,14 v=-18,22 -1 477 p=3,68 v=-15,86 -1 478 p=87,15 v=11,37 -1 479 p=4,57 v=-9,-61 -1 480 p=23,37 v=-82,-22 -1 481 p=9,77 v=-76,-37 -1 482 p=32,7 v=-21,60 -1 483 p=43,69 v=-50,95 -1 484 p=90,55 v=4,-43 -1 485 p=58,34 v=59,-27 -1 486 p=44,2 v=45,-24 -1 487 p=32,91 v=67,29 -1 488 p=52,35 v=-26,-60 -1 489 p=80,102 v=90,-20 -1 490 p=5,59 v=-43,-75 -1 491 p=51,57 v=45,70 -1 492 p=90,65 v=51,16 -1 493 p=54,40 v=-74,79 -1 494 p=47,12 v=-33,-54 -1 495 p=71,80 v=-85,-37 -1 496 p=24,12 v=-28,-50 -1 497 p=50,8 v=-79,61 -1 498 p=27,86 v=65,-30 -1 499 p=25,46 v=16,48 -1 500 p=5,3 v=-76,-90
diff --git a/2024/14/solution.rs b/2024/14/solution.rs
@@ -0,0 +1,83 @@ -1 1 #[path = "../lib.rs"] -1 2 mod lib; -1 3 -1 4 fn parse_xy(s: &str) -> Option<(i64, i64)> { -1 5 let (_, ss) = s.split_once('=')?; -1 6 let (xs, ys) = ss.split_once(',')?; -1 7 let x = xs.parse::<i64>().ok()?; -1 8 let y = ys.parse::<i64>().ok()?; -1 9 return Some((x, y)); -1 10 } -1 11 -1 12 fn parse_line(s: &str) -> Option<(i64, i64, i64, i64)> { -1 13 let (ps, vs) = s.split_once(' ')?; -1 14 let (px, py) = parse_xy(ps)?; -1 15 let (vx, vy) = parse_xy(vs)?; -1 16 return Some((px, py, vx, vy)); -1 17 } -1 18 -1 19 fn print(bots: &Vec<(i64, i64, i64, i64)>, w: i64, h: i64) { -1 20 let mut map = vec![vec![0; w as usize]; h as usize]; -1 21 for (x, y, _, _) in bots.iter() { -1 22 map[*y as usize][*x as usize] += 1; -1 23 } -1 24 for row in map.iter() { -1 25 for c in row.iter() { -1 26 if *c == 0 { -1 27 print!(" "); -1 28 } else { -1 29 print!("{}", c); -1 30 } -1 31 } -1 32 println!(""); -1 33 } -1 34 println!(""); -1 35 } -1 36 -1 37 fn part2() { -1 38 // store output to a file and search for many consecutive 1s -1 39 let w = 101; -1 40 let h = 103; -1 41 let mut bots = vec![]; -1 42 -1 43 for line in lib::iter_input() { -1 44 bots.push(parse_line(&line).unwrap()); -1 45 } -1 46 -1 47 for i in 0.. { -1 48 println!("{}", i); -1 49 print(&bots, w, h); -1 50 bots = bots.iter().map(|(px, py, vx, vy)| { -1 51 let x = (px + vx).rem_euclid(w); -1 52 let y = (py + vy).rem_euclid(h); -1 53 return (x, y, *vx, *vy); -1 54 }).collect(); -1 55 } -1 56 } -1 57 -1 58 fn main() { -1 59 let mut quadrants = [0, 0, 0, 0]; -1 60 -1 61 let w = 101; -1 62 let h = 103; -1 63 let t = 100; -1 64 -1 65 for line in lib::iter_input() { -1 66 let (px, py, vx, vy) = parse_line(&line).unwrap(); -1 67 let x = (px + vx * t).rem_euclid(w); -1 68 let y = (py + vy * t).rem_euclid(h); -1 69 if x < w / 2 && y < h / 2 { -1 70 quadrants[0] += 1; -1 71 } else if x < w / 2 && y > h / 2 { -1 72 quadrants[1] += 1; -1 73 } else if x > w / 2 && y < h / 2 { -1 74 quadrants[2] += 1; -1 75 } else if x > w / 2 && y > h / 2 { -1 76 quadrants[3] += 1; -1 77 } -1 78 } -1 79 -1 80 println!("part1: {}", quadrants.iter().fold(1, |a, b| a * b)); -1 81 -1 82 part2(); -1 83 }
diff --git a/2024/14/test.txt b/2024/14/test.txt
@@ -0,0 +1,12 @@ -1 1 p=0,4 v=3,-3 -1 2 p=6,3 v=-1,-3 -1 3 p=10,3 v=-1,2 -1 4 p=2,0 v=2,-1 -1 5 p=0,0 v=1,3 -1 6 p=3,0 v=-2,-2 -1 7 p=7,6 v=-1,-3 -1 8 p=3,0 v=-1,-2 -1 9 p=9,3 v=2,3 -1 10 p=7,3 v=-1,2 -1 11 p=2,4 v=2,-3 -1 12 p=9,5 v=-3,-3