From f8be82378e621601143b5543992644142839c9e1 Mon Sep 17 00:00:00 2001 From: Andrej Orsula Date: Fri, 13 Dec 2024 22:48:58 +0100 Subject: [PATCH] aoc2024/day13: Add solution Signed-off-by: Andrej Orsula --- README.md | 2 +- aoc2024/input/2024/day13.txt | 1279 ++++++++++++++++++++++++++++++++++ aoc2024/src/day13.rs | 112 +++ aoc2024/src/lib.rs | 2 +- 4 files changed, 1393 insertions(+), 2 deletions(-) create mode 100644 aoc2024/input/2024/day13.txt create mode 100644 aoc2024/src/day13.rs diff --git a/README.md b/README.md index 9719868..be7484c 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ My solutions to [Advent of Code](https://adventofcode.com) puzzles. | 10 | [Hoof It](https://adventofcode.com/2024/day/10) | [day10.rs](aoc2024/src/day10.rs) | 210.9 µs | 82.03 µs | | 11 | [Plutonian Pebbles](https://adventofcode.com/2024/day/11) | [day11.rs](aoc2024/src/day11.rs) | 215.0 µs | 5.208 ms | | 12 | [Garden Groups](https://adventofcode.com/2024/day/12) | [day12.rs](aoc2024/src/day12.rs) | 1.319 ms | 1.974 ms | +| 13 | [Claw Contraption](https://adventofcode.com/2024/day/13) | [day13.rs](aoc2024/src/day13.rs) | 87.33 µs | 72.88 µs | - diff --git a/aoc2024/input/2024/day13.txt b/aoc2024/input/2024/day13.txt new file mode 100644 index 0000000..13b993a --- /dev/null +++ b/aoc2024/input/2024/day13.txt @@ -0,0 +1,1279 @@ +Button A: X+73, Y+53 +Button B: X+11, Y+32 +Prize: X=4660, Y=4632 + +Button A: X+41, Y+19 +Button B: X+17, Y+78 +Prize: X=3267, Y=3828 + +Button A: X+75, Y+43 +Button B: X+20, Y+46 +Prize: X=6855, Y=7349 + +Button A: X+56, Y+95 +Button B: X+51, Y+22 +Prize: X=7715, Y=7862 + +Button A: X+34, Y+14 +Button B: X+28, Y+54 +Prize: X=3818, Y=15772 + +Button A: X+80, Y+46 +Button B: X+25, Y+92 +Prize: X=5725, Y=9890 + +Button A: X+83, Y+12 +Button B: X+11, Y+72 +Prize: X=1590, Y=9032 + +Button A: X+48, Y+20 +Button B: X+13, Y+52 +Prize: X=9457, Y=17044 + +Button A: X+95, Y+45 +Button B: X+39, Y+90 +Prize: X=5765, Y=7380 + +Button A: X+83, Y+71 +Button B: X+78, Y+12 +Prize: X=11195, Y=4925 + +Button A: X+55, Y+16 +Button B: X+19, Y+47 +Prize: X=9186, Y=7178 + +Button A: X+38, Y+86 +Button B: X+62, Y+12 +Prize: X=4474, Y=5506 + +Button A: X+63, Y+14 +Button B: X+14, Y+62 +Prize: X=2076, Y=17238 + +Button A: X+39, Y+25 +Button B: X+12, Y+35 +Prize: X=19553, Y=12970 + +Button A: X+50, Y+21 +Button B: X+38, Y+64 +Prize: X=3660, Y=19021 + +Button A: X+24, Y+52 +Button B: X+50, Y+26 +Prize: X=3100, Y=3588 + +Button A: X+66, Y+20 +Button B: X+12, Y+54 +Prize: X=13046, Y=9600 + +Button A: X+29, Y+61 +Button B: X+48, Y+26 +Prize: X=12520, Y=3434 + +Button A: X+43, Y+24 +Button B: X+26, Y+47 +Prize: X=3437, Y=1434 + +Button A: X+58, Y+34 +Button B: X+11, Y+58 +Prize: X=2216, Y=6248 + +Button A: X+36, Y+83 +Button B: X+70, Y+19 +Prize: X=8572, Y=7233 + +Button A: X+70, Y+76 +Button B: X+63, Y+17 +Prize: X=7063, Y=7103 + +Button A: X+60, Y+20 +Button B: X+44, Y+53 +Prize: X=7584, Y=5633 + +Button A: X+20, Y+59 +Button B: X+67, Y+33 +Prize: X=2942, Y=1328 + +Button A: X+29, Y+40 +Button B: X+80, Y+32 +Prize: X=4079, Y=1944 + +Button A: X+79, Y+36 +Button B: X+61, Y+87 +Prize: X=7513, Y=7035 + +Button A: X+46, Y+78 +Button B: X+47, Y+19 +Prize: X=10323, Y=5047 + +Button A: X+17, Y+69 +Button B: X+49, Y+15 +Prize: X=5109, Y=9503 + +Button A: X+63, Y+51 +Button B: X+11, Y+83 +Prize: X=2497, Y=4837 + +Button A: X+42, Y+88 +Button B: X+60, Y+33 +Prize: X=3150, Y=3355 + +Button A: X+98, Y+78 +Button B: X+27, Y+98 +Prize: X=7563, Y=13288 + +Button A: X+23, Y+45 +Button B: X+54, Y+31 +Prize: X=8948, Y=18689 + +Button A: X+27, Y+27 +Button B: X+84, Y+17 +Prize: X=3693, Y=1415 + +Button A: X+73, Y+53 +Button B: X+38, Y+92 +Prize: X=4729, Y=5881 + +Button A: X+14, Y+94 +Button B: X+17, Y+21 +Prize: X=1024, Y=4640 + +Button A: X+25, Y+47 +Button B: X+33, Y+20 +Prize: X=2579, Y=11743 + +Button A: X+47, Y+61 +Button B: X+94, Y+27 +Prize: X=10998, Y=6484 + +Button A: X+21, Y+67 +Button B: X+47, Y+16 +Prize: X=530, Y=10209 + +Button A: X+65, Y+16 +Button B: X+13, Y+43 +Prize: X=6282, Y=3362 + +Button A: X+94, Y+41 +Button B: X+18, Y+80 +Prize: X=2748, Y=7692 + +Button A: X+62, Y+85 +Button B: X+51, Y+12 +Prize: X=3789, Y=4905 + +Button A: X+47, Y+57 +Button B: X+11, Y+83 +Prize: X=4693, Y=10707 + +Button A: X+15, Y+28 +Button B: X+32, Y+15 +Prize: X=13995, Y=19144 + +Button A: X+25, Y+59 +Button B: X+36, Y+21 +Prize: X=4398, Y=6030 + +Button A: X+57, Y+77 +Button B: X+57, Y+17 +Prize: X=912, Y=992 + +Button A: X+15, Y+76 +Button B: X+77, Y+82 +Prize: X=1913, Y=3838 + +Button A: X+28, Y+11 +Button B: X+22, Y+32 +Prize: X=11830, Y=969 + +Button A: X+56, Y+34 +Button B: X+26, Y+53 +Prize: X=688, Y=7638 + +Button A: X+81, Y+34 +Button B: X+41, Y+88 +Prize: X=8278, Y=5740 + +Button A: X+46, Y+70 +Button B: X+45, Y+19 +Prize: X=9988, Y=11008 + +Button A: X+95, Y+36 +Button B: X+63, Y+80 +Prize: X=10121, Y=5912 + +Button A: X+75, Y+15 +Button B: X+19, Y+79 +Prize: X=1894, Y=11854 + +Button A: X+41, Y+26 +Button B: X+34, Y+82 +Prize: X=2722, Y=3358 + +Button A: X+93, Y+48 +Button B: X+26, Y+49 +Prize: X=2775, Y=1539 + +Button A: X+37, Y+95 +Button B: X+51, Y+24 +Prize: X=2414, Y=2455 + +Button A: X+81, Y+88 +Button B: X+87, Y+21 +Prize: X=2991, Y=1338 + +Button A: X+69, Y+42 +Button B: X+21, Y+44 +Prize: X=19601, Y=8090 + +Button A: X+24, Y+45 +Button B: X+41, Y+13 +Prize: X=16223, Y=11183 + +Button A: X+97, Y+58 +Button B: X+18, Y+49 +Prize: X=4654, Y=4427 + +Button A: X+43, Y+52 +Button B: X+97, Y+18 +Prize: X=5609, Y=3506 + +Button A: X+38, Y+82 +Button B: X+85, Y+36 +Prize: X=6625, Y=4124 + +Button A: X+33, Y+77 +Button B: X+49, Y+16 +Prize: X=440, Y=4565 + +Button A: X+20, Y+51 +Button B: X+50, Y+29 +Prize: X=2550, Y=14419 + +Button A: X+22, Y+42 +Button B: X+53, Y+18 +Prize: X=15593, Y=8918 + +Button A: X+78, Y+13 +Button B: X+57, Y+94 +Prize: X=4224, Y=6619 + +Button A: X+84, Y+13 +Button B: X+13, Y+81 +Prize: X=4404, Y=5853 + +Button A: X+59, Y+11 +Button B: X+26, Y+84 +Prize: X=979, Y=3581 + +Button A: X+48, Y+72 +Button B: X+98, Y+41 +Prize: X=6070, Y=2851 + +Button A: X+22, Y+57 +Button B: X+39, Y+21 +Prize: X=4715, Y=13574 + +Button A: X+65, Y+28 +Button B: X+14, Y+45 +Prize: X=16964, Y=17891 + +Button A: X+83, Y+16 +Button B: X+46, Y+97 +Prize: X=3178, Y=3521 + +Button A: X+48, Y+23 +Button B: X+24, Y+86 +Prize: X=5256, Y=8106 + +Button A: X+90, Y+46 +Button B: X+36, Y+79 +Prize: X=3708, Y=6925 + +Button A: X+38, Y+12 +Button B: X+35, Y+58 +Prize: X=15735, Y=9058 + +Button A: X+80, Y+97 +Button B: X+75, Y+24 +Prize: X=4370, Y=1684 + +Button A: X+37, Y+73 +Button B: X+32, Y+13 +Prize: X=6653, Y=10947 + +Button A: X+25, Y+71 +Button B: X+42, Y+15 +Prize: X=6839, Y=1934 + +Button A: X+69, Y+59 +Button B: X+20, Y+58 +Prize: X=6741, Y=9813 + +Button A: X+28, Y+78 +Button B: X+45, Y+13 +Prize: X=16468, Y=16864 + +Button A: X+52, Y+19 +Button B: X+46, Y+78 +Prize: X=5280, Y=6947 + +Button A: X+92, Y+89 +Button B: X+12, Y+56 +Prize: X=8636, Y=10352 + +Button A: X+39, Y+62 +Button B: X+42, Y+12 +Prize: X=14165, Y=16698 + +Button A: X+11, Y+65 +Button B: X+77, Y+57 +Prize: X=6908, Y=5398 + +Button A: X+50, Y+27 +Button B: X+32, Y+62 +Prize: X=17898, Y=2463 + +Button A: X+86, Y+22 +Button B: X+92, Y+96 +Prize: X=13514, Y=9834 + +Button A: X+88, Y+22 +Button B: X+53, Y+86 +Prize: X=8027, Y=8918 + +Button A: X+32, Y+19 +Button B: X+16, Y+43 +Prize: X=17152, Y=17138 + +Button A: X+18, Y+28 +Button B: X+99, Y+13 +Prize: X=8667, Y=3189 + +Button A: X+16, Y+47 +Button B: X+52, Y+27 +Prize: X=2304, Y=3247 + +Button A: X+12, Y+65 +Button B: X+74, Y+27 +Prize: X=1826, Y=3939 + +Button A: X+16, Y+68 +Button B: X+40, Y+11 +Prize: X=8568, Y=5293 + +Button A: X+14, Y+45 +Button B: X+73, Y+30 +Prize: X=17699, Y=19640 + +Button A: X+22, Y+67 +Button B: X+64, Y+15 +Prize: X=8218, Y=6635 + +Button A: X+33, Y+14 +Button B: X+22, Y+45 +Prize: X=8955, Y=17458 + +Button A: X+15, Y+58 +Button B: X+79, Y+26 +Prize: X=11445, Y=15710 + +Button A: X+13, Y+24 +Button B: X+41, Y+20 +Prize: X=5690, Y=8024 + +Button A: X+68, Y+22 +Button B: X+13, Y+38 +Prize: X=16928, Y=10484 + +Button A: X+66, Y+15 +Button B: X+27, Y+36 +Prize: X=6081, Y=3801 + +Button A: X+22, Y+48 +Button B: X+55, Y+27 +Prize: X=19108, Y=2576 + +Button A: X+65, Y+86 +Button B: X+94, Y+19 +Prize: X=3955, Y=1018 + +Button A: X+53, Y+48 +Button B: X+16, Y+76 +Prize: X=1949, Y=4164 + +Button A: X+27, Y+60 +Button B: X+53, Y+29 +Prize: X=4637, Y=9296 + +Button A: X+33, Y+17 +Button B: X+29, Y+55 +Prize: X=15320, Y=15152 + +Button A: X+38, Y+65 +Button B: X+53, Y+22 +Prize: X=2410, Y=6085 + +Button A: X+60, Y+16 +Button B: X+24, Y+77 +Prize: X=2216, Y=563 + +Button A: X+68, Y+26 +Button B: X+15, Y+41 +Prize: X=2716, Y=2308 + +Button A: X+21, Y+47 +Button B: X+36, Y+19 +Prize: X=16370, Y=18716 + +Button A: X+55, Y+34 +Button B: X+23, Y+45 +Prize: X=15126, Y=19666 + +Button A: X+16, Y+44 +Button B: X+72, Y+57 +Prize: X=3328, Y=3230 + +Button A: X+44, Y+15 +Button B: X+35, Y+55 +Prize: X=7217, Y=12945 + +Button A: X+15, Y+43 +Button B: X+82, Y+70 +Prize: X=5141, Y=5989 + +Button A: X+33, Y+11 +Button B: X+32, Y+53 +Prize: X=7227, Y=16818 + +Button A: X+55, Y+26 +Button B: X+13, Y+44 +Prize: X=9071, Y=18452 + +Button A: X+53, Y+25 +Button B: X+15, Y+41 +Prize: X=2221, Y=17391 + +Button A: X+53, Y+28 +Button B: X+15, Y+55 +Prize: X=4634, Y=1949 + +Button A: X+75, Y+14 +Button B: X+19, Y+79 +Prize: X=18246, Y=17559 + +Button A: X+62, Y+80 +Button B: X+48, Y+15 +Prize: X=7668, Y=7125 + +Button A: X+22, Y+66 +Button B: X+82, Y+24 +Prize: X=5558, Y=3354 + +Button A: X+51, Y+16 +Button B: X+25, Y+59 +Prize: X=7980, Y=2819 + +Button A: X+58, Y+24 +Button B: X+31, Y+69 +Prize: X=15401, Y=9431 + +Button A: X+32, Y+11 +Button B: X+19, Y+61 +Prize: X=5674, Y=16720 + +Button A: X+50, Y+91 +Button B: X+86, Y+32 +Prize: X=11742, Y=9292 + +Button A: X+78, Y+18 +Button B: X+16, Y+42 +Prize: X=6154, Y=3642 + +Button A: X+38, Y+78 +Button B: X+53, Y+16 +Prize: X=15936, Y=890 + +Button A: X+68, Y+75 +Button B: X+14, Y+76 +Prize: X=718, Y=2427 + +Button A: X+85, Y+29 +Button B: X+12, Y+66 +Prize: X=9431, Y=18515 + +Button A: X+14, Y+85 +Button B: X+81, Y+50 +Prize: X=4858, Y=4755 + +Button A: X+30, Y+42 +Button B: X+95, Y+27 +Prize: X=6825, Y=2241 + +Button A: X+46, Y+24 +Button B: X+15, Y+34 +Prize: X=8557, Y=8006 + +Button A: X+15, Y+46 +Button B: X+71, Y+31 +Prize: X=3557, Y=7666 + +Button A: X+16, Y+84 +Button B: X+74, Y+14 +Prize: X=3906, Y=16734 + +Button A: X+62, Y+32 +Button B: X+19, Y+50 +Prize: X=3147, Y=10154 + +Button A: X+21, Y+81 +Button B: X+57, Y+13 +Prize: X=10781, Y=11657 + +Button A: X+36, Y+87 +Button B: X+87, Y+31 +Prize: X=4755, Y=4142 + +Button A: X+31, Y+35 +Button B: X+11, Y+81 +Prize: X=2420, Y=2938 + +Button A: X+44, Y+12 +Button B: X+24, Y+66 +Prize: X=14380, Y=11924 + +Button A: X+12, Y+48 +Button B: X+76, Y+26 +Prize: X=3300, Y=10072 + +Button A: X+30, Y+58 +Button B: X+28, Y+12 +Prize: X=5316, Y=5844 + +Button A: X+39, Y+61 +Button B: X+93, Y+26 +Prize: X=5469, Y=2581 + +Button A: X+33, Y+61 +Button B: X+97, Y+51 +Prize: X=3087, Y=2627 + +Button A: X+72, Y+21 +Button B: X+20, Y+72 +Prize: X=14108, Y=13349 + +Button A: X+83, Y+37 +Button B: X+68, Y+95 +Prize: X=8858, Y=9059 + +Button A: X+14, Y+47 +Button B: X+70, Y+18 +Prize: X=4806, Y=10538 + +Button A: X+99, Y+19 +Button B: X+73, Y+64 +Prize: X=4831, Y=1727 + +Button A: X+45, Y+14 +Button B: X+31, Y+63 +Prize: X=17763, Y=6612 + +Button A: X+15, Y+26 +Button B: X+52, Y+24 +Prize: X=13850, Y=7420 + +Button A: X+14, Y+84 +Button B: X+65, Y+22 +Prize: X=6569, Y=6662 + +Button A: X+13, Y+61 +Button B: X+92, Y+30 +Prize: X=6919, Y=5151 + +Button A: X+20, Y+42 +Button B: X+43, Y+12 +Prize: X=3325, Y=4172 + +Button A: X+66, Y+29 +Button B: X+38, Y+81 +Prize: X=9198, Y=9443 + +Button A: X+16, Y+38 +Button B: X+75, Y+18 +Prize: X=958, Y=674 + +Button A: X+17, Y+43 +Button B: X+46, Y+19 +Prize: X=3396, Y=1989 + +Button A: X+18, Y+60 +Button B: X+68, Y+31 +Prize: X=14426, Y=17441 + +Button A: X+17, Y+36 +Button B: X+60, Y+28 +Prize: X=18097, Y=12708 + +Button A: X+75, Y+79 +Button B: X+98, Y+20 +Prize: X=5859, Y=3425 + +Button A: X+69, Y+44 +Button B: X+12, Y+31 +Prize: X=4736, Y=5052 + +Button A: X+27, Y+68 +Button B: X+26, Y+12 +Prize: X=2105, Y=2360 + +Button A: X+23, Y+97 +Button B: X+86, Y+90 +Prize: X=2694, Y=8362 + +Button A: X+51, Y+11 +Button B: X+44, Y+86 +Prize: X=12360, Y=15182 + +Button A: X+44, Y+15 +Button B: X+13, Y+66 +Prize: X=14320, Y=9878 + +Button A: X+23, Y+73 +Button B: X+82, Y+59 +Prize: X=5085, Y=5070 + +Button A: X+62, Y+15 +Button B: X+16, Y+51 +Prize: X=3538, Y=1421 + +Button A: X+17, Y+71 +Button B: X+52, Y+48 +Prize: X=1191, Y=1929 + +Button A: X+89, Y+68 +Button B: X+14, Y+36 +Prize: X=823, Y=1312 + +Button A: X+74, Y+71 +Button B: X+18, Y+97 +Prize: X=6010, Y=6165 + +Button A: X+11, Y+63 +Button B: X+68, Y+68 +Prize: X=6649, Y=7221 + +Button A: X+91, Y+35 +Button B: X+22, Y+29 +Prize: X=6359, Y=3370 + +Button A: X+97, Y+36 +Button B: X+14, Y+41 +Prize: X=3268, Y=4113 + +Button A: X+52, Y+61 +Button B: X+89, Y+18 +Prize: X=12534, Y=6927 + +Button A: X+37, Y+77 +Button B: X+50, Y+14 +Prize: X=5777, Y=557 + +Button A: X+96, Y+65 +Button B: X+28, Y+81 +Prize: X=6612, Y=7641 + +Button A: X+47, Y+26 +Button B: X+19, Y+44 +Prize: X=12450, Y=16732 + +Button A: X+93, Y+13 +Button B: X+98, Y+92 +Prize: X=8912, Y=3908 + +Button A: X+37, Y+74 +Button B: X+55, Y+13 +Prize: X=16410, Y=13629 + +Button A: X+11, Y+67 +Button B: X+93, Y+47 +Prize: X=6658, Y=9386 + +Button A: X+55, Y+87 +Button B: X+62, Y+13 +Prize: X=5253, Y=3290 + +Button A: X+23, Y+52 +Button B: X+37, Y+15 +Prize: X=8531, Y=4837 + +Button A: X+72, Y+40 +Button B: X+17, Y+52 +Prize: X=15403, Y=9636 + +Button A: X+48, Y+19 +Button B: X+29, Y+75 +Prize: X=5448, Y=6730 + +Button A: X+34, Y+84 +Button B: X+97, Y+38 +Prize: X=2480, Y=3304 + +Button A: X+65, Y+18 +Button B: X+41, Y+75 +Prize: X=7006, Y=6459 + +Button A: X+40, Y+14 +Button B: X+14, Y+39 +Prize: X=8696, Y=18964 + +Button A: X+18, Y+62 +Button B: X+55, Y+39 +Prize: X=3108, Y=3484 + +Button A: X+15, Y+55 +Button B: X+37, Y+17 +Prize: X=8456, Y=9716 + +Button A: X+73, Y+26 +Button B: X+22, Y+71 +Prize: X=14127, Y=6928 + +Button A: X+66, Y+37 +Button B: X+30, Y+60 +Prize: X=9854, Y=11703 + +Button A: X+52, Y+11 +Button B: X+19, Y+80 +Prize: X=3423, Y=5566 + +Button A: X+87, Y+33 +Button B: X+32, Y+46 +Prize: X=6457, Y=4955 + +Button A: X+16, Y+36 +Button B: X+65, Y+28 +Prize: X=14877, Y=12440 + +Button A: X+59, Y+11 +Button B: X+24, Y+54 +Prize: X=14000, Y=10736 + +Button A: X+81, Y+61 +Button B: X+12, Y+46 +Prize: X=8325, Y=9707 + +Button A: X+12, Y+57 +Button B: X+72, Y+19 +Prize: X=8432, Y=18227 + +Button A: X+52, Y+35 +Button B: X+12, Y+94 +Prize: X=5104, Y=9450 + +Button A: X+20, Y+78 +Button B: X+40, Y+12 +Prize: X=5320, Y=7212 + +Button A: X+19, Y+30 +Button B: X+34, Y+15 +Prize: X=4745, Y=7205 + +Button A: X+18, Y+71 +Button B: X+66, Y+27 +Prize: X=1776, Y=2572 + +Button A: X+42, Y+78 +Button B: X+56, Y+27 +Prize: X=4592, Y=4293 + +Button A: X+77, Y+24 +Button B: X+11, Y+64 +Prize: X=3454, Y=4832 + +Button A: X+51, Y+13 +Button B: X+14, Y+33 +Prize: X=6571, Y=17420 + +Button A: X+48, Y+28 +Button B: X+26, Y+53 +Prize: X=1540, Y=15566 + +Button A: X+20, Y+54 +Button B: X+60, Y+11 +Prize: X=1580, Y=19510 + +Button A: X+39, Y+12 +Button B: X+18, Y+30 +Prize: X=3717, Y=2220 + +Button A: X+79, Y+11 +Button B: X+34, Y+35 +Prize: X=5530, Y=3161 + +Button A: X+51, Y+16 +Button B: X+33, Y+60 +Prize: X=13952, Y=7340 + +Button A: X+85, Y+31 +Button B: X+41, Y+68 +Prize: X=8130, Y=4026 + +Button A: X+33, Y+58 +Button B: X+47, Y+12 +Prize: X=16240, Y=10260 + +Button A: X+12, Y+46 +Button B: X+47, Y+18 +Prize: X=13413, Y=16222 + +Button A: X+62, Y+37 +Button B: X+17, Y+35 +Prize: X=4677, Y=16499 + +Button A: X+16, Y+76 +Button B: X+59, Y+16 +Prize: X=14402, Y=18040 + +Button A: X+39, Y+78 +Button B: X+76, Y+27 +Prize: X=6542, Y=2709 + +Button A: X+18, Y+42 +Button B: X+45, Y+13 +Prize: X=11420, Y=508 + +Button A: X+67, Y+87 +Button B: X+57, Y+14 +Prize: X=8551, Y=8943 + +Button A: X+47, Y+69 +Button B: X+33, Y+13 +Prize: X=761, Y=19601 + +Button A: X+34, Y+67 +Button B: X+57, Y+28 +Prize: X=1795, Y=18480 + +Button A: X+93, Y+73 +Button B: X+13, Y+81 +Prize: X=8592, Y=10992 + +Button A: X+34, Y+13 +Button B: X+37, Y+67 +Prize: X=5153, Y=215 + +Button A: X+30, Y+11 +Button B: X+33, Y+69 +Prize: X=3417, Y=2903 + +Button A: X+53, Y+29 +Button B: X+12, Y+34 +Prize: X=14515, Y=11623 + +Button A: X+21, Y+59 +Button B: X+66, Y+12 +Prize: X=19451, Y=1875 + +Button A: X+62, Y+39 +Button B: X+12, Y+30 +Prize: X=11842, Y=14129 + +Button A: X+33, Y+75 +Button B: X+59, Y+11 +Prize: X=14683, Y=19489 + +Button A: X+59, Y+29 +Button B: X+18, Y+52 +Prize: X=17494, Y=13270 + +Button A: X+22, Y+55 +Button B: X+55, Y+18 +Prize: X=13905, Y=1697 + +Button A: X+14, Y+92 +Button B: X+81, Y+15 +Prize: X=5445, Y=4227 + +Button A: X+12, Y+33 +Button B: X+29, Y+16 +Prize: X=15296, Y=19469 + +Button A: X+69, Y+86 +Button B: X+52, Y+18 +Prize: X=5117, Y=4318 + +Button A: X+22, Y+75 +Button B: X+53, Y+16 +Prize: X=5458, Y=6091 + +Button A: X+86, Y+39 +Button B: X+40, Y+97 +Prize: X=7498, Y=4110 + +Button A: X+17, Y+34 +Button B: X+94, Y+26 +Prize: X=2395, Y=2684 + +Button A: X+83, Y+40 +Button B: X+11, Y+50 +Prize: X=12027, Y=10330 + +Button A: X+55, Y+25 +Button B: X+26, Y+46 +Prize: X=5632, Y=15272 + +Button A: X+88, Y+18 +Button B: X+18, Y+86 +Prize: X=2256, Y=4742 + +Button A: X+41, Y+54 +Button B: X+74, Y+16 +Prize: X=4634, Y=2356 + +Button A: X+17, Y+51 +Button B: X+40, Y+13 +Prize: X=8639, Y=15053 + +Button A: X+19, Y+61 +Button B: X+92, Y+31 +Prize: X=7563, Y=7626 + +Button A: X+54, Y+18 +Button B: X+12, Y+66 +Prize: X=4112, Y=6056 + +Button A: X+52, Y+19 +Button B: X+23, Y+46 +Prize: X=19633, Y=4121 + +Button A: X+69, Y+12 +Button B: X+12, Y+79 +Prize: X=17456, Y=7991 + +Button A: X+95, Y+89 +Button B: X+16, Y+69 +Prize: X=9602, Y=11264 + +Button A: X+12, Y+74 +Button B: X+85, Y+25 +Prize: X=10717, Y=13569 + +Button A: X+66, Y+39 +Button B: X+23, Y+46 +Prize: X=2341, Y=1281 + +Button A: X+44, Y+18 +Button B: X+16, Y+26 +Prize: X=1480, Y=19340 + +Button A: X+80, Y+51 +Button B: X+13, Y+33 +Prize: X=9278, Y=566 + +Button A: X+11, Y+56 +Button B: X+54, Y+12 +Prize: X=11789, Y=9548 + +Button A: X+79, Y+41 +Button B: X+14, Y+49 +Prize: X=7568, Y=12014 + +Button A: X+91, Y+26 +Button B: X+44, Y+96 +Prize: X=6112, Y=8504 + +Button A: X+16, Y+64 +Button B: X+82, Y+46 +Prize: X=1994, Y=4310 + +Button A: X+13, Y+46 +Button B: X+70, Y+12 +Prize: X=15508, Y=6664 + +Button A: X+62, Y+14 +Button B: X+14, Y+61 +Prize: X=4402, Y=11916 + +Button A: X+13, Y+29 +Button B: X+44, Y+18 +Prize: X=5370, Y=5776 + +Button A: X+43, Y+54 +Button B: X+82, Y+15 +Prize: X=8013, Y=1881 + +Button A: X+43, Y+92 +Button B: X+82, Y+36 +Prize: X=7803, Y=5400 + +Button A: X+24, Y+60 +Button B: X+42, Y+13 +Prize: X=13712, Y=1608 + +Button A: X+22, Y+82 +Button B: X+83, Y+59 +Prize: X=6690, Y=7410 + +Button A: X+47, Y+15 +Button B: X+21, Y+36 +Prize: X=11319, Y=14069 + +Button A: X+85, Y+38 +Button B: X+11, Y+78 +Prize: X=3827, Y=6242 + +Button A: X+11, Y+20 +Button B: X+56, Y+33 +Prize: X=9618, Y=9578 + +Button A: X+15, Y+52 +Button B: X+72, Y+19 +Prize: X=7745, Y=10414 + +Button A: X+76, Y+20 +Button B: X+56, Y+71 +Prize: X=6064, Y=3565 + +Button A: X+31, Y+14 +Button B: X+15, Y+36 +Prize: X=3028, Y=1952 + +Button A: X+64, Y+13 +Button B: X+65, Y+94 +Prize: X=4200, Y=4085 + +Button A: X+52, Y+29 +Button B: X+22, Y+43 +Prize: X=4438, Y=3735 + +Button A: X+33, Y+53 +Button B: X+34, Y+16 +Prize: X=13726, Y=8092 + +Button A: X+49, Y+18 +Button B: X+14, Y+52 +Prize: X=19597, Y=15034 + +Button A: X+18, Y+42 +Button B: X+53, Y+35 +Prize: X=7121, Y=6563 + +Button A: X+33, Y+14 +Button B: X+35, Y+58 +Prize: X=18482, Y=12668 + +Button A: X+19, Y+41 +Button B: X+58, Y+28 +Prize: X=5038, Y=3196 + +Button A: X+46, Y+23 +Button B: X+29, Y+51 +Prize: X=8567, Y=13523 + +Button A: X+77, Y+27 +Button B: X+65, Y+84 +Prize: X=10980, Y=9114 + +Button A: X+60, Y+14 +Button B: X+13, Y+76 +Prize: X=12936, Y=6200 + +Button A: X+49, Y+15 +Button B: X+37, Y+63 +Prize: X=14117, Y=1019 + +Button A: X+57, Y+16 +Button B: X+11, Y+25 +Prize: X=468, Y=16323 + +Button A: X+41, Y+98 +Button B: X+21, Y+15 +Prize: X=1757, Y=3179 + +Button A: X+15, Y+55 +Button B: X+87, Y+85 +Prize: X=3612, Y=7160 + +Button A: X+27, Y+72 +Button B: X+63, Y+14 +Prize: X=5418, Y=7210 + +Button A: X+22, Y+92 +Button B: X+81, Y+83 +Prize: X=4526, Y=6652 + +Button A: X+95, Y+41 +Button B: X+34, Y+89 +Prize: X=1657, Y=2053 + +Button A: X+37, Y+54 +Button B: X+92, Y+12 +Prize: X=10424, Y=3720 + +Button A: X+30, Y+54 +Button B: X+59, Y+30 +Prize: X=18217, Y=8210 + +Button A: X+14, Y+41 +Button B: X+62, Y+35 +Prize: X=8164, Y=3304 + +Button A: X+99, Y+74 +Button B: X+28, Y+90 +Prize: X=4139, Y=4268 + +Button A: X+61, Y+13 +Button B: X+26, Y+74 +Prize: X=14879, Y=12575 + +Button A: X+83, Y+49 +Button B: X+14, Y+44 +Prize: X=12990, Y=1602 + +Button A: X+34, Y+23 +Button B: X+21, Y+64 +Prize: X=5390, Y=8526 + +Button A: X+52, Y+98 +Button B: X+63, Y+12 +Prize: X=7621, Y=5504 + +Button A: X+14, Y+98 +Button B: X+34, Y+36 +Prize: X=296, Y=1062 + +Button A: X+86, Y+16 +Button B: X+24, Y+66 +Prize: X=4998, Y=1176 + +Button A: X+90, Y+11 +Button B: X+57, Y+71 +Prize: X=4056, Y=1008 + +Button A: X+82, Y+49 +Button B: X+15, Y+64 +Prize: X=7329, Y=5095 + +Button A: X+59, Y+17 +Button B: X+51, Y+79 +Prize: X=5989, Y=2433 + +Button A: X+33, Y+64 +Button B: X+46, Y+23 +Prize: X=15084, Y=382 + +Button A: X+18, Y+34 +Button B: X+51, Y+19 +Prize: X=11369, Y=17657 + +Button A: X+16, Y+51 +Button B: X+70, Y+32 +Prize: X=15212, Y=6882 + +Button A: X+41, Y+64 +Button B: X+49, Y+23 +Prize: X=4593, Y=18868 + +Button A: X+62, Y+28 +Button B: X+11, Y+43 +Prize: X=4623, Y=5853 + +Button A: X+37, Y+20 +Button B: X+48, Y+97 +Prize: X=4387, Y=8482 + +Button A: X+43, Y+91 +Button B: X+85, Y+52 +Prize: X=11478, Y=12909 + +Button A: X+50, Y+33 +Button B: X+28, Y+80 +Prize: X=6314, Y=9581 + +Button A: X+49, Y+11 +Button B: X+39, Y+72 +Prize: X=11497, Y=5646 + +Button A: X+21, Y+14 +Button B: X+24, Y+83 +Prize: X=3570, Y=7070 + +Button A: X+20, Y+63 +Button B: X+90, Y+30 +Prize: X=5180, Y=3642 + +Button A: X+83, Y+45 +Button B: X+43, Y+99 +Prize: X=7801, Y=6273 + +Button A: X+14, Y+45 +Button B: X+52, Y+18 +Prize: X=18594, Y=8639 + +Button A: X+22, Y+95 +Button B: X+91, Y+46 +Prize: X=3917, Y=4077 + +Button A: X+13, Y+49 +Button B: X+98, Y+41 +Prize: X=9889, Y=5749 + +Button A: X+80, Y+12 +Button B: X+12, Y+54 +Prize: X=18892, Y=11126 + +Button A: X+54, Y+21 +Button B: X+13, Y+40 +Prize: X=12105, Y=1875 + +Button A: X+20, Y+98 +Button B: X+90, Y+29 +Prize: X=2110, Y=1687 + +Button A: X+69, Y+42 +Button B: X+12, Y+39 +Prize: X=6479, Y=2915 + +Button A: X+48, Y+14 +Button B: X+19, Y+73 +Prize: X=1102, Y=1662 + +Button A: X+44, Y+30 +Button B: X+15, Y+38 +Prize: X=12842, Y=1728 + +Button A: X+16, Y+31 +Button B: X+47, Y+18 +Prize: X=3092, Y=16620 + +Button A: X+25, Y+73 +Button B: X+85, Y+13 +Prize: X=7585, Y=5449 + +Button A: X+38, Y+17 +Button B: X+17, Y+40 +Prize: X=19201, Y=11152 + +Button A: X+27, Y+15 +Button B: X+12, Y+41 +Prize: X=14879, Y=16276 + +Button A: X+16, Y+65 +Button B: X+66, Y+18 +Prize: X=16602, Y=8590 + +Button A: X+39, Y+16 +Button B: X+34, Y+54 +Prize: X=15971, Y=12796 + +Button A: X+16, Y+56 +Button B: X+74, Y+22 +Prize: X=3556, Y=18492 + +Button A: X+96, Y+27 +Button B: X+38, Y+50 +Prize: X=5736, Y=2085 + +Button A: X+90, Y+69 +Button B: X+11, Y+39 +Prize: X=3049, Y=5058 diff --git a/aoc2024/src/day13.rs b/aoc2024/src/day13.rs new file mode 100644 index 0000000..5159a3a --- /dev/null +++ b/aoc2024/src/day13.rs @@ -0,0 +1,112 @@ +use aoc_runner_derive::aoc; + +#[aoc(day13, part1)] +#[must_use] +pub fn part1(input: &str) -> i64 { + Problem::parse(input).solve() +} + +#[aoc(day13, part2)] +#[must_use] +pub fn part2(input: &str) -> i64 { + let mut problem = Problem::parse(input); + problem.iter_mut().for_each(|behaviour| { + behaviour.goal += nalgebra::Vector2::from_element(10_000_000_000_000); + }); + problem.solve() +} + +#[derive(derive_more::Deref, derive_more::DerefMut)] +struct Problem(Vec); + +struct Behaviour { + a_button: nalgebra::Vector2, + b_button: nalgebra::Vector2, + goal: nalgebra::Vector2, +} + +impl Problem { + fn parse(input: &str) -> Self { + Self( + input + .split("\n\n") + .map(|x| { + let mut lines = x.split('\n'); + let a = Self::parse_inner(lines.next().unwrap()); + let b = Self::parse_inner(lines.next().unwrap()); + + let (_, prize) = lines.next().unwrap().rsplit_once(": ").unwrap(); + let (x, y) = prize.split_once(", ").unwrap(); + let prize = (x[2..].parse().unwrap(), y[2..].parse().unwrap()); + + Behaviour { + a_button: nalgebra::Vector2::new(a.0, a.1), + b_button: nalgebra::Vector2::new(b.0, b.1), + goal: nalgebra::Vector2::new(prize.0, prize.1), + } + }) + .collect(), + ) + } + + fn parse_inner(line: &str) -> (i64, i64) { + let (_, parts) = line.rsplit_once(": ").unwrap(); + let (x, y) = parts.split_once(", ").unwrap(); + (x[1..].parse().unwrap(), y[1..].parse().unwrap()) + } + + fn solve(&self) -> i64 { + self.iter() + .map(|behaviour| { + let a = (behaviour.b_button.y * behaviour.goal.x + - behaviour.b_button.x * behaviour.goal.y) + / (behaviour.a_button.x * behaviour.b_button.y + - behaviour.a_button.y * behaviour.b_button.x); + let b = (behaviour.goal.x - behaviour.a_button.x * a) / behaviour.b_button.x; + + if a <= 0 + || b <= 0 + || behaviour.goal != behaviour.a_button * a + behaviour.b_button * b + { + 0 + } else { + 3 * a + b + } + }) + .sum() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use indoc::indoc; + + const SAMPLE: &str = indoc! {" + Button A: X+94, Y+34 + Button B: X+22, Y+67 + Prize: X=8400, Y=5400 + + Button A: X+26, Y+66 + Button B: X+67, Y+21 + Prize: X=12748, Y=12176 + + Button A: X+17, Y+86 + Button B: X+84, Y+37 + Prize: X=7870, Y=6450 + + Button A: X+69, Y+23 + Button B: X+27, Y+71 + Prize: X=18641, Y=10279 + "}; + + #[test] + pub fn part1_example() { + assert_eq!(part1(SAMPLE), 480); + } + + #[test] + pub fn part2_example() { + assert_eq!(part2(SAMPLE), 875_318_608_908); + } +} diff --git a/aoc2024/src/lib.rs b/aoc2024/src/lib.rs index 318383a..8b0bafc 100644 --- a/aoc2024/src/lib.rs +++ b/aoc2024/src/lib.rs @@ -11,7 +11,7 @@ pub mod day9; pub mod day10; pub mod day11; pub mod day12; -// pub mod day13; +pub mod day13; // pub mod day14; // pub mod day15; // pub mod day16;