diff --git a/2024/day16/solution.c b/2024/day16/solution.c index 50909bf..a21463f 100644 --- a/2024/day16/solution.c +++ b/2024/day16/solution.c @@ -64,12 +64,14 @@ int64_t _2024_day16_part1(const char * input, int length) struct dijkstra_xy16 prev[width * height]; int dist[width * height]; + int turn_cost = 1000; dijkstra_cartesian(input, stride, width, height, start_x, start_y, end_x, end_y, '#', + turn_cost, prev, dist); diff --git a/2024/day18/input.txt b/2024/day18/input.txt new file mode 100644 index 0000000..652cbfa --- /dev/null +++ b/2024/day18/input.txt @@ -0,0 +1,3450 @@ +57,61 +69,61 +25,3 +43,60 +7,14 +62,37 +7,6 +9,15 +4,21 +33,1 +66,53 +22,9 +33,4 +70,69 +40,65 +23,17 +67,42 +18,13 +65,59 +3,6 +43,67 +55,62 +68,51 +44,49 +29,1 +65,35 +21,1 +5,29 +49,69 +26,13 +24,19 +56,53 +18,5 +9,25 +45,61 +13,27 +67,34 +65,31 +67,59 +9,17 +55,65 +63,30 +66,29 +65,47 +45,68 +7,23 +49,65 +29,21 +15,5 +34,59 +20,5 +49,47 +69,63 +9,3 +23,5 +13,14 +53,39 +47,51 +15,21 +15,4 +19,7 +29,61 +17,20 +67,30 +65,51 +55,63 +47,44 +59,35 +26,7 +46,65 +42,7 +5,13 +58,65 +59,52 +9,19 +27,2 +39,62 +17,23 +7,5 +9,16 +65,67 +61,66 +9,7 +51,51 +27,15 +12,15 +58,35 +3,26 +69,27 +58,57 +1,5 +60,61 +5,11 +9,9 +35,11 +61,59 +65,62 +27,16 +13,9 +30,21 +37,63 +33,68 +9,5 +53,69 +47,57 +43,58 +57,62 +15,9 +42,69 +39,9 +13,10 +20,11 +17,1 +14,11 +67,48 +55,43 +30,17 +39,2 +33,56 +44,53 +1,9 +7,13 +1,19 +67,56 +28,19 +62,47 +51,56 +25,7 +65,27 +63,61 +63,37 +27,17 +33,2 +69,66 +39,65 +38,59 +43,65 +67,33 +45,63 +61,63 +14,7 +42,61 +19,16 +58,55 +45,49 +65,29 +51,58 +21,13 +5,10 +21,16 +17,10 +66,49 +1,10 +1,2 +69,28 +60,67 +53,53 +66,33 +59,39 +67,37 +67,57 +37,64 +21,21 +13,5 +63,36 +62,31 +11,8 +33,13 +48,33 +29,3 +69,24 +63,27 +47,59 +57,36 +69,37 +5,1 +2,17 +63,45 +63,39 +25,1 +45,69 +61,28 +5,27 +59,49 +59,37 +25,13 +22,13 +33,5 +69,57 +27,7 +27,19 +61,57 +48,69 +57,59 +57,49 +18,7 +24,11 +28,7 +47,43 +25,25 +62,39 +67,47 +9,1 +68,53 +38,45 +13,2 +9,11 +23,27 +63,50 +63,42 +3,21 +63,34 +43,54 +57,42 +3,3 +40,57 +29,24 +17,18 +53,37 +56,51 +23,13 +13,1 +11,19 +43,61 +1,11 +5,24 +3,10 +65,23 +61,29 +16,7 +1,17 +9,18 +61,61 +32,15 +63,47 +7,9 +5,3 +66,37 +41,52 +37,43 +27,10 +47,69 +23,24 +8,23 +51,47 +57,41 +1,20 +67,49 +3,22 +67,26 +29,23 +64,47 +54,47 +41,55 +15,14 +55,37 +57,50 +49,63 +60,57 +13,24 +32,19 +57,43 +69,29 +1,13 +53,49 +27,25 +49,61 +64,63 +11,20 +31,3 +62,59 +40,59 +10,13 +57,63 +7,12 +50,41 +67,45 +48,53 +35,19 +5,26 +59,27 +67,21 +59,47 +47,42 +49,60 +0,17 +6,1 +39,69 +29,22 +69,21 +3,17 +11,17 +53,45 +29,20 +2,23 +58,49 +63,65 +45,52 +64,35 +21,5 +19,11 +10,25 +7,1 +49,59 +45,51 +2,3 +21,15 +25,22 +49,50 +53,59 +21,17 +14,17 +45,47 +60,63 +47,33 +40,7 +67,62 +68,63 +23,1 +54,39 +69,49 +34,57 +7,19 +23,11 +59,34 +38,63 +55,46 +17,2 +53,58 +51,61 +54,41 +9,21 +11,0 +67,69 +59,57 +55,35 +51,67 +23,14 +46,51 +69,43 +11,5 +57,67 +17,16 +55,49 +55,61 +59,51 +61,69 +28,25 +65,41 +51,43 +4,15 +27,24 +63,31 +69,51 +2,27 +54,49 +61,45 +68,47 +67,68 +29,0 +47,48 +53,63 +29,25 +1,15 +65,68 +15,27 +19,13 +65,45 +24,25 +48,59 +50,69 +49,40 +13,23 +69,69 +7,28 +31,4 +42,23 +20,17 +61,41 +45,59 +66,41 +58,69 +5,7 +23,2 +54,53 +60,35 +55,60 +55,47 +43,44 +56,67 +12,13 +35,7 +56,45 +31,6 +59,53 +39,51 +25,15 +70,55 +47,65 +29,15 +61,55 +65,69 +23,19 +57,54 +8,11 +51,69 +3,14 +62,65 +19,19 +23,9 +47,63 +5,4 +47,53 +31,5 +15,3 +65,57 +61,31 +49,56 +13,4 +25,4 +24,1 +51,39 +63,69 +43,66 +43,69 +64,29 +17,15 +21,26 +17,11 +23,7 +69,33 +41,61 +30,29 +15,6 +47,67 +62,27 +12,23 +60,51 +55,69 +43,59 +2,7 +43,63 +53,48 +65,61 +61,51 +8,5 +37,67 +64,57 +9,27 +49,62 +26,11 +59,45 +47,62 +57,40 +53,47 +69,25 +4,19 +37,58 +21,10 +11,12 +3,25 +69,42 +31,25 +34,9 +31,29 +62,69 +49,45 +68,33 +27,9 +5,9 +54,69 +51,38 +70,45 +61,27 +27,11 +55,57 +62,49 +63,52 +3,31 +11,3 +67,39 +63,56 +39,53 +57,45 +10,23 +8,15 +26,23 +47,52 +44,65 +60,39 +7,2 +13,13 +51,66 +3,8 +45,41 +59,33 +55,30 +59,69 +66,57 +59,31 +45,4 +29,31 +37,57 +11,1 +45,67 +61,64 +5,15 +17,12 +11,18 +31,23 +43,1 +17,5 +57,55 +45,58 +29,2 +67,63 +20,1 +5,8 +53,57 +42,67 +53,61 +47,54 +65,60 +37,7 +17,7 +27,27 +33,21 +39,66 +12,17 +53,36 +61,32 +65,37 +13,19 +54,43 +59,67 +33,6 +36,69 +1,3 +15,17 +37,59 +9,10 +51,44 +69,56 +5,25 +53,50 +59,30 +25,9 +1,0 +41,53 +69,67 +49,42 +4,17 +13,3 +3,12 +11,6 +34,13 +69,53 +5,12 +31,17 +6,3 +37,5 +50,53 +68,41 +70,37 +31,18 +63,25 +21,23 +61,54 +18,1 +57,37 +65,25 +59,55 +45,55 +68,59 +46,57 +45,62 +49,57 +53,56 +10,7 +67,27 +51,57 +43,53 +57,25 +43,51 +45,40 +69,60 +46,63 +51,59 +49,55 +67,51 +5,5 +43,57 +65,53 +25,8 +67,29 +48,45 +5,17 +51,49 +15,24 +69,50 +5,21 +40,49 +57,57 +35,3 +46,69 +27,4 +41,45 +21,19 +31,27 +63,57 +67,55 +6,9 +9,2 +64,59 +24,9 +1,28 +50,49 +65,40 +63,33 +27,21 +33,8 +53,55 +21,25 +16,21 +15,18 +55,29 +22,7 +37,68 +53,65 +19,23 +48,57 +1,4 +47,9 +29,7 +42,63 +3,5 +15,22 +27,14 +22,3 +69,55 +3,9 +57,28 +67,25 +52,61 +65,64 +39,67 +25,27 +25,5 +65,66 +19,1 +11,21 +67,53 +39,49 +70,49 +51,45 +69,64 +51,63 +35,57 +67,23 +36,11 +35,50 +3,19 +69,59 +56,57 +51,55 +19,17 +56,69 +63,44 +65,39 +53,43 +69,62 +63,35 +7,17 +17,17 +61,46 +20,7 +59,60 +62,33 +47,61 +41,48 +6,23 +1,7 +15,2 +11,15 +44,55 +65,63 +27,18 +17,9 +67,35 +11,9 +67,58 +7,7 +25,26 +65,54 +46,67 +69,47 +52,47 +20,23 +7,8 +31,1 +29,12 +22,5 +31,21 +5,19 +41,56 +29,4 +15,11 +13,8 +61,39 +65,21 +27,3 +25,11 +67,67 +56,39 +17,3 +7,22 +27,5 +35,5 +39,70 +67,46 +19,2 +49,51 +67,54 +67,44 +11,26 +15,13 +63,63 +3,1 +22,21 +57,60 +23,23 +13,15 +43,50 +11,22 +45,45 +5,23 +41,16 +23,0 +69,45 +32,21 +52,67 +53,64 +31,2 +62,51 +54,67 +61,22 +67,43 +4,1 +69,65 +15,15 +65,43 +6,19 +13,29 +7,3 +27,13 +60,49 +13,17 +37,69 +1,23 +67,38 +40,61 +44,63 +52,51 +9,4 +67,22 +55,66 +65,22 +26,21 +63,41 +63,51 +19,3 +65,33 +10,33 +23,18 +9,13 +63,55 +51,54 +19,9 +15,19 +22,17 +18,27 +9,23 +66,45 +17,21 +39,5 +21,7 +59,32 +25,6 +35,63 +59,46 +48,49 +23,25 +53,70 +1,1 +63,62 +6,15 +39,68 +35,53 +69,41 +67,61 +27,66 +25,16 +45,60 +48,67 +25,23 +59,42 +60,69 +19,25 +57,47 +15,10 +27,23 +41,69 +59,59 +28,59 +3,24 +63,67 +57,48 +43,47 +29,59 +61,53 +52,63 +31,8 +10,17 +57,38 +16,25 +30,9 +39,43 +49,43 +59,38 +67,65 +69,23 +58,45 +58,63 +19,8 +61,40 +62,61 +19,15 +45,43 +49,64 +42,47 +61,65 +61,35 +34,21 +15,25 +21,20 +59,61 +21,31 +41,65 +15,23 +55,45 +19,5 +21,12 +65,46 +50,67 +55,67 +13,20 +31,26 +21,9 +69,31 +25,18 +65,26 +65,52 +37,66 +23,3 +66,31 +13,11 +61,58 +60,37 +45,65 +36,63 +35,69 +7,16 +15,1 +17,19 +37,8 +21,29 +15,16 +7,11 +41,51 +17,27 +41,64 +63,53 +55,51 +61,33 +35,1 +3,15 +14,21 +57,69 +36,65 +33,7 +19,14 +33,9 +52,43 +49,67 +55,52 +23,21 +31,19 +18,9 +42,45 +3,11 +43,55 +69,39 +31,7 +22,23 +23,15 +25,19 +68,39 +36,9 +63,59 +5,30 +51,53 +68,23 +67,66 +55,64 +36,1 +64,43 +57,51 +61,47 +21,11 +0,9 +59,63 +53,67 +28,13 +3,29 +68,69 +13,0 +21,3 +54,59 +61,43 +19,27 +65,50 +65,49 +17,4 +56,43 +45,44 +63,49 +39,63 +48,41 +49,46 +63,68 +41,67 +11,11 +64,27 +61,67 +11,2 +2,19 +27,1 +45,53 +51,60 +24,21 +67,41 +14,27 +60,45 +50,63 +53,35 +67,28 +58,67 +1,14 +32,69 +0,21 +29,19 +42,57 +20,19 +45,56 +29,6 +51,52 +50,47 +29,11 +65,55 +67,24 +7,25 +15,7 +62,43 +46,5 +28,9 +67,31 +55,39 +8,21 +51,65 +29,5 +44,69 +2,13 +67,36 +54,55 +53,51 +70,33 +11,31 +60,55 +16,13 +63,43 +18,19 +58,43 +29,9 +31,24 +24,13 +47,55 +24,5 +9,30 +49,53 +11,10 +66,65 +26,1 +17,13 +55,55 +4,5 +13,7 +25,17 +61,37 +11,23 +70,27 +37,60 +62,55 +13,21 +55,56 +47,47 +7,20 +35,60 +48,65 +64,39 +11,13 +41,63 +12,5 +8,7 +68,31 +56,19 +21,67 +41,31 +40,25 +7,32 +55,17 +45,13 +17,25 +64,13 +42,9 +13,25 +21,39 +19,37 +13,37 +64,23 +45,19 +5,39 +5,67 +39,45 +63,16 +26,55 +29,27 +46,1 +35,54 +11,51 +31,66 +39,25 +21,24 +37,48 +42,39 +52,41 +69,35 +52,1 +3,61 +17,56 +11,28 +44,13 +53,33 +37,11 +55,23 +33,51 +5,42 +7,57 +39,55 +46,19 +43,2 +29,29 +61,15 +64,9 +54,37 +21,47 +25,50 +65,0 +18,23 +45,21 +40,45 +12,59 +35,16 +50,23 +41,0 +57,30 +54,13 +3,49 +47,3 +52,7 +50,31 +51,5 +4,35 +38,53 +34,27 +20,35 +53,31 +46,17 +7,21 +33,30 +15,45 +56,13 +3,30 +42,33 +20,45 +17,31 +33,15 +28,57 +45,42 +19,42 +3,7 +69,11 +7,53 +67,15 +49,17 +11,38 +23,49 +22,61 +0,41 +15,33 +1,31 +7,63 +37,27 +45,31 +19,63 +49,11 +55,59 +28,65 +4,63 +48,23 +3,63 +41,23 +11,49 +37,50 +27,31 +13,59 +65,15 +54,23 +27,42 +22,33 +57,21 +30,47 +7,40 +16,59 +19,44 +3,67 +15,49 +46,47 +15,35 +10,55 +41,3 +25,63 +29,70 +7,61 +23,56 +67,4 +61,13 +7,47 +18,29 +57,15 +11,55 +29,57 +35,37 +32,59 +37,34 +41,22 +35,59 +1,27 +13,65 +1,39 +32,29 +29,45 +51,14 +5,53 +57,33 +15,50 +43,21 +47,8 +54,29 +35,9 +5,40 +5,54 +13,26 +19,68 +35,20 +40,5 +5,61 +41,24 +17,41 +9,67 +49,9 +41,25 +63,11 +11,53 +30,63 +20,33 +63,29 +59,65 +13,36 +8,61 +60,29 +23,30 +57,11 +7,38 +14,49 +57,24 +25,49 +42,5 +55,19 +26,61 +63,9 +7,15 +19,53 +31,34 +3,68 +18,69 +1,70 +3,50 +19,22 +38,23 +23,65 +67,1 +28,33 +2,45 +61,6 +7,45 +47,15 +5,38 +69,19 +9,44 +50,3 +3,38 +15,39 +42,17 +19,57 +25,64 +23,42 +15,41 +33,61 +32,47 +11,67 +7,56 +3,56 +33,39 +5,32 +57,8 +38,7 +1,33 +51,26 +45,15 +15,51 +63,22 +61,11 +37,37 +63,21 +7,29 +28,53 +41,43 +14,57 +58,9 +17,43 +43,29 +11,25 +55,9 +29,52 +41,35 +7,68 +63,23 +34,31 +38,25 +23,38 +55,13 +5,47 +15,37 +35,25 +19,38 +42,37 +4,61 +40,37 +5,51 +59,11 +25,70 +65,1 +30,59 +25,61 +32,51 +13,51 +21,51 +49,25 +16,63 +37,15 +15,31 +25,28 +61,19 +56,33 +20,41 +30,69 +32,53 +43,5 +8,43 +41,7 +21,58 +31,37 +6,69 +34,51 +15,68 +21,52 +27,39 +53,19 +34,17 +37,55 +8,27 +61,2 +47,38 +39,3 +47,20 +0,37 +39,27 +3,39 +23,64 +41,39 +23,35 +39,57 +0,65 +43,11 +2,61 +5,59 +47,25 +15,55 +16,49 +39,29 +46,15 +33,11 +33,52 +17,62 +3,60 +44,39 +51,15 +41,37 +20,27 +12,51 +35,0 +63,3 +29,68 +5,66 +38,5 +33,49 +44,21 +25,39 +21,35 +8,37 +39,39 +69,9 +59,13 +9,65 +1,61 +13,57 +47,29 +10,31 +47,27 +27,36 +65,14 +53,5 +47,36 +58,15 +51,3 +9,29 +53,7 +27,69 +51,21 +39,47 +19,69 +29,65 +15,43 +34,11 +13,67 +9,49 +49,31 +7,35 +49,38 +23,68 +61,18 +59,12 +44,15 +53,41 +5,60 +31,35 +49,41 +57,6 +45,29 +20,67 +67,9 +51,35 +38,19 +1,51 +34,61 +49,26 +28,35 +2,43 +46,39 +20,65 +25,40 +22,69 +15,57 +51,10 +54,25 +37,14 +11,35 +5,65 +9,52 +57,64 +27,44 +65,65 +4,51 +22,41 +33,29 +9,64 +27,51 +47,30 +35,35 +8,35 +15,34 +39,23 +19,35 +34,67 +49,32 +31,10 +40,9 +58,19 +67,17 +42,31 +57,5 +21,45 +24,47 +9,41 +47,2 +41,47 +52,11 +23,43 +17,57 +43,12 +59,26 +57,23 +36,53 +8,65 +57,16 +3,45 +59,17 +63,13 +43,33 +25,41 +21,49 +57,1 +49,39 +14,55 +28,63 +57,53 +27,45 +31,12 +5,63 +29,37 +33,27 +15,63 +23,63 +12,69 +40,33 +1,41 +45,35 +67,10 +17,45 +9,69 +13,61 +33,35 +7,65 +51,37 +57,35 +16,55 +41,49 +45,27 +1,43 +65,9 +9,35 +31,58 +45,9 +8,55 +15,32 +67,3 +36,31 +25,33 +53,12 +57,9 +37,22 +38,27 +25,51 +49,13 +37,49 +7,59 +69,20 +37,29 +52,17 +15,65 +5,35 +67,5 +21,61 +19,21 +43,26 +16,43 +45,36 +35,22 +17,54 +58,1 +15,69 +65,4 +48,35 +35,41 +42,41 +45,11 +49,4 +45,23 +7,51 +3,35 +42,19 +59,22 +29,43 +35,31 +63,8 +44,37 +37,36 +55,18 +39,21 +35,33 +48,21 +40,35 +49,15 +21,63 +37,30 +25,60 +26,27 +31,63 +11,57 +51,19 +65,13 +2,63 +19,30 +59,9 +38,47 +1,49 +38,41 +32,13 +2,65 +51,33 +51,27 +17,46 +53,9 +13,53 +22,55 +9,61 +1,29 +27,59 +25,62 +34,65 +15,58 +37,46 +33,41 +49,29 +19,33 +18,33 +55,28 +61,3 +3,41 +11,43 +17,53 +1,63 +42,35 +62,25 +27,57 +33,25 +11,7 +43,46 +3,59 +9,31 +41,17 +19,64 +27,48 +25,32 +6,45 +14,53 +27,49 +33,48 +12,47 +7,27 +23,31 +49,19 +45,7 +5,41 +66,19 +29,63 +59,23 +39,14 +49,23 +42,3 +24,53 +17,39 +23,55 +2,41 +31,49 +27,68 +48,25 +54,15 +35,67 +47,31 +37,21 +35,44 +39,40 +69,6 +38,55 +6,63 +46,27 +18,65 +45,22 +25,65 +70,15 +63,20 +1,56 +59,25 +8,31 +19,41 +9,55 +69,36 +11,50 +27,33 +23,67 +22,47 +17,37 +45,5 +33,23 +49,2 +41,18 +41,14 +10,51 +24,43 +19,65 +29,49 +18,57 +55,15 +41,28 +58,11 +33,31 +15,40 +42,11 +0,59 +41,11 +43,41 +46,49 +33,46 +7,41 +28,61 +17,29 +17,33 +59,10 +25,69 +63,15 +3,33 +35,47 +31,50 +57,27 +27,63 +35,45 +69,18 +59,15 +3,36 +53,29 +49,21 +49,7 +59,3 +26,47 +43,49 +39,35 +50,7 +16,41 +29,41 +9,43 +27,29 +32,37 +13,31 +33,67 +65,20 +50,19 +59,43 +44,7 +53,15 +28,27 +37,56 +29,38 +11,29 +11,54 +56,7 +56,25 +31,61 +32,65 +13,33 +54,7 +8,51 +12,41 +16,31 +66,5 +37,51 +9,58 +39,16 +39,33 +61,12 +4,65 +30,15 +13,42 +21,65 +35,42 +27,67 +6,65 +5,69 +17,52 +7,67 +5,50 +7,69 +4,57 +33,37 +1,67 +65,10 +67,13 +45,57 +59,4 +43,28 +68,19 +17,61 +1,52 +13,30 +65,2 +13,41 +55,21 +8,25 +14,39 +57,29 +1,47 +1,30 +37,1 +53,21 +13,45 +31,9 +31,13 +53,3 +43,9 +19,51 +23,53 +33,55 +49,8 +47,41 +30,51 +13,44 +17,36 +55,25 +44,17 +26,41 +34,41 +43,23 +35,15 +19,45 +14,31 +31,59 +12,33 +9,37 +17,63 +49,37 +41,59 +21,36 +59,1 +13,63 +29,42 +51,9 +28,55 +36,5 +61,25 +36,49 +47,6 +49,5 +43,45 +61,4 +63,1 +61,1 +65,17 +18,47 +21,57 +29,51 +45,39 +7,37 +31,55 +53,11 +68,9 +1,53 +25,52 +65,7 +36,39 +43,3 +45,17 +31,62 +39,19 +1,55 +53,1 +23,41 +57,32 +8,53 +9,33 +23,37 +25,47 +27,65 +51,25 +36,57 +47,39 +1,21 +15,67 +49,0 +68,1 +47,23 +37,3 +3,55 +20,29 +9,39 +17,59 +47,35 +29,13 +68,15 +8,69 +21,53 +37,25 +15,44 +27,47 +38,15 +5,45 +35,23 +35,6 +40,1 +15,28 +48,11 +11,61 +39,12 +5,31 +29,32 +37,20 +1,37 +18,35 +27,50 +51,20 +43,4 +45,30 +31,47 +51,4 +33,33 +46,25 +6,47 +43,15 +29,40 +37,61 +3,47 +33,59 +30,55 +21,32 +23,54 +39,17 +31,15 +24,65 +62,15 +47,19 +41,33 +25,67 +18,55 +55,1 +52,3 +69,5 +3,69 +47,1 +11,45 +47,37 +29,30 +63,2 +43,7 +19,59 +41,27 +9,51 +5,55 +60,25 +3,13 +53,34 +27,53 +15,61 +3,52 +19,58 +31,36 +6,55 +43,43 +54,9 +3,53 +53,23 +25,43 +19,49 +17,60 +41,54 +51,24 +23,51 +20,53 +42,27 +5,58 +18,51 +44,31 +66,9 +35,61 +40,43 +3,37 +23,39 +0,25 +60,1 +39,13 +3,32 +43,35 +19,62 +34,37 +57,39 +18,43 +50,35 +51,28 +27,43 +17,55 +36,45 +27,30 +51,12 +19,40 +31,41 +57,19 +41,42 +59,5 +2,49 +15,47 +38,35 +10,43 +29,67 +31,39 +9,60 +35,51 +5,37 +43,17 +37,45 +9,46 +42,51 +45,20 +69,1 +25,58 +10,57 +41,1 +29,33 +21,38 +63,6 +47,5 +51,34 +37,19 +31,46 +37,38 +5,33 +19,60 +16,67 +30,27 +11,65 +53,18 +35,27 +57,7 +55,3 +13,55 +29,55 +23,59 +19,43 +52,39 +28,49 +21,46 +45,46 +61,8 +15,53 +53,13 +5,48 +8,63 +32,43 +26,39 +47,45 +50,15 +2,57 +11,37 +11,33 +35,17 +13,35 +10,69 +12,57 +55,2 +26,57 +14,67 +55,14 +47,49 +63,7 +47,13 +37,13 +23,69 +31,57 +31,33 +32,61 +66,17 +51,11 +7,46 +27,61 +31,40 +52,45 +38,43 +35,21 +43,27 +23,66 +31,51 +11,66 +31,69 +13,48 +60,17 +33,47 +56,1 +39,22 +31,67 +49,35 +5,43 +1,59 +37,28 +60,7 +47,21 +53,32 +19,39 +37,2 +34,35 +30,35 +22,29 +53,17 +43,39 +51,22 +31,65 +47,14 +30,43 +40,11 +61,9 +54,33 +40,19 +51,17 +19,29 +56,11 +23,46 +29,35 +7,55 +67,12 +29,17 +8,67 +61,21 +43,25 +11,63 +39,32 +32,23 +33,44 +19,48 +67,11 +33,57 +8,49 +25,57 +3,54 +19,67 +58,25 +47,7 +4,45 +37,42 +6,61 +11,27 +55,10 +67,7 +17,35 +23,47 +39,30 +39,37 +17,51 +33,10 +11,68 +11,47 +37,35 +7,33 +52,31 +26,53 +9,59 +55,4 +61,16 +7,49 +13,43 +13,47 +53,26 +37,47 +51,13 +48,27 +11,36 +17,38 +58,3 +6,33 +51,41 +29,39 +26,31 +50,29 +7,31 +9,40 +24,31 +59,14 +26,33 +53,25 +46,33 +55,33 +11,64 +37,31 +51,1 +25,31 +25,45 +39,31 +35,65 +16,47 +64,17 +26,65 +61,24 +15,36 +47,11 +9,63 +5,49 +27,35 +63,5 +55,53 +21,69 +59,29 +36,27 +61,17 +68,13 +28,39 +11,69 +61,49 +41,9 +19,61 +63,4 +55,5 +51,29 +49,3 +4,69 +23,40 +34,47 +23,57 +17,65 +52,29 +19,55 +21,59 +33,40 +33,53 +57,4 +61,7 +25,44 +67,2 +47,17 +17,49 +21,41 +45,34 +23,33 +49,12 +11,44 +23,60 +14,61 +33,69 +3,43 +57,31 +49,27 +48,13 +57,18 +57,17 +10,61 +22,27 +62,11 +17,40 +49,49 +63,17 +69,7 +19,50 +24,59 +21,33 +43,37 +59,20 +12,61 +65,11 +13,52 +53,27 +31,11 +53,62 +35,29 +24,49 +30,65 +55,31 +39,41 +22,57 +43,10 +13,34 +51,31 +0,33 +35,13 +37,32 +25,37 +37,12 +39,7 +33,19 +67,6 +16,29 +63,19 +32,41 +27,55 +9,47 +27,37 +6,27 +33,45 +40,29 +61,5 +69,4 +43,13 +59,19 +49,1 +36,17 +21,50 +1,57 +44,33 +31,31 +3,65 +45,1 +1,48 +39,52 +31,43 +5,36 +21,37 +42,21 +6,51 +56,35 +25,35 +41,57 +1,69 +33,17 +15,29 +9,45 +10,41 +57,65 +51,7 +48,17 +1,25 +2,39 +3,27 +45,3 +41,15 +31,45 +29,69 +33,65 +35,49 +2,67 +37,4 +57,22 +65,24 +14,63 +7,39 +29,53 +25,21 +54,1 +25,36 +22,65 +36,35 +21,27 +46,11 +41,29 +57,13 +54,5 +48,29 +39,59 +34,3 +21,55 +29,48 +41,21 +31,53 +45,24 +49,33 +13,66 +35,14 +69,3 +28,45 +37,53 +9,53 +15,64 +40,51 +14,47 +3,28 +65,12 +55,11 +37,41 +13,69 +31,56 +70,11 +21,34 +46,9 +4,43 +60,43 +19,47 +55,41 +53,20 +45,32 +36,25 +0,45 +9,57 +18,25 +6,43 +9,34 +23,61 +39,15 +37,18 +61,23 +37,39 +34,25 +39,11 +25,29 +57,3 +61,10 +25,34 +9,48 +31,32 +52,23 +12,55 +22,43 +59,21 +54,21 +17,32 +56,21 +51,23 +32,33 +36,37 +43,19 +69,15 +12,63 +20,55 +34,55 +45,25 +23,45 +5,57 +12,29 +68,17 +33,43 +11,46 +34,29 +2,35 +41,5 +31,54 +7,43 +17,47 +59,41 +55,7 +23,29 +53,16 +40,39 +45,6 +17,70 +29,16 +11,41 +23,36 +1,35 +29,47 +55,27 +27,41 +13,39 +25,68 +25,55 +67,19 +9,28 +64,7 +65,19 +11,59 +41,19 +41,13 +37,65 +3,57 +19,31 +44,1 +25,38 +43,14 +69,8 +14,45 +43,31 +35,24 +32,27 +33,3 +66,15 +34,33 +7,58 +21,48 +65,3 +21,43 +1,65 +69,17 +49,10 +61,20 +39,61 +37,17 +45,28 +31,38 +10,37 +45,33 +17,66 +31,14 +37,33 +45,37 +37,9 +0,53 +35,43 +3,51 +6,35 +61,14 +1,45 +21,62 +15,59 +39,1 +8,41 +13,60 +51,6 +34,63 +41,41 +22,51 +69,13 +59,7 +13,49 +51,36 +11,39 +13,38 +3,46 +65,5 +3,23 +49,16 +25,59 +35,55 +17,69 +33,63 +17,67 +49,18 +37,23 +3,34 +25,53 +35,39 +52,19 +44,47 +68,10 +64,22 +28,4 +2,64 +62,45 +15,54 +50,60 +66,3 +40,52 +34,54 +6,40 +56,18 +30,53 +47,4 +52,16 +2,34 +50,36 +60,34 +0,42 +18,66 +52,48 +8,56 +2,69 +46,58 +44,50 +51,48 +12,49 +47,12 +42,50 +59,64 +54,58 +70,29 +24,44 +65,42 +58,59 +46,68 +9,70 +44,42 +51,68 +32,50 +40,42 +24,63 +33,50 +69,38 +10,6 +2,31 +66,12 +33,66 +31,48 +52,13 +12,46 +65,30 +18,70 +20,52 +48,4 +50,61 +4,34 +66,44 +52,40 +22,70 +36,68 +33,38 +18,60 +37,70 +26,63 +22,31 +2,47 +30,52 +60,30 +34,43 +39,10 +43,6 +30,70 +11,60 +53,42 +18,32 +8,70 +9,22 +6,17 +48,54 +59,48 +42,25 +56,49 +40,3 +32,36 +18,48 +42,58 +6,58 +68,2 +70,39 +51,16 +30,54 +10,19 +66,0 +17,50 +15,52 +1,16 +4,39 +45,50 +68,7 +36,34 +48,8 +44,26 +2,12 +26,34 +32,30 +5,44 +17,44 +14,43 +42,1 +63,48 +58,37 +35,66 +56,23 +0,12 +66,18 +18,0 +22,56 +49,44 +20,40 +48,47 +66,69 +58,53 +37,40 +58,36 +32,62 +0,31 +46,45 +10,38 +34,5 +17,42 +65,18 +21,56 +11,58 +17,68 +13,54 +18,39 +11,4 +30,45 +12,67 +20,46 +59,28 +66,6 +46,21 +56,22 +64,28 +10,32 +49,52 +43,0 +31,68 +17,0 +19,70 +26,5 +1,64 +2,51 +68,43 +30,64 +35,32 +22,50 +58,5 +4,53 +44,52 +60,42 +18,45 +48,36 +44,61 +12,53 +34,70 +51,46 +22,2 +34,10 +62,70 +1,26 +50,57 +24,32 +56,62 +20,0 +30,32 +56,63 +53,28 +66,47 +52,18 +64,50 +19,54 +6,52 +13,46 +22,36 +68,22 +38,1 +10,30 +0,67 +62,50 +19,52 +4,47 +14,32 +19,36 +38,46 +39,54 +14,40 +6,67 +21,0 +38,70 +35,28 +23,58 +36,3 +26,64 +55,26 +26,70 +66,8 +46,55 +42,62 +13,70 +28,64 +51,50 +8,45 +0,32 +52,62 +46,13 +32,68 +15,48 +0,64 +32,70 +48,46 +20,68 +62,41 +34,40 +3,18 +12,27 +0,24 +10,4 +40,30 +26,43 +6,48 +39,8 +12,70 +2,50 +5,70 +35,46 +59,40 +26,37 +29,46 +48,63 +68,11 +2,52 +62,36 +16,48 +20,32 +0,16 +44,0 +20,69 +41,46 +62,28 +2,15 +54,48 +56,17 +26,52 +3,44 +22,38 +30,50 +40,63 +13,68 +47,46 +8,60 +6,41 +30,62 +42,0 +37,6 +30,41 +32,46 +66,22 +39,44 +6,28 +29,60 +1,66 +28,41 +11,62 +49,58 +4,62 +34,48 +4,49 +0,34 +42,64 +10,36 +34,14 +44,58 +60,52 +9,66 +10,46 +68,24 +7,50 +27,58 +16,40 +44,45 +7,64 +54,50 +30,58 +70,14 +62,64 +6,53 +22,60 +0,55 +34,15 +69,34 +25,54 +7,26 +22,45 +6,20 +55,42 +8,18 +6,31 +22,59 +14,58 +68,21 +18,67 +28,44 +63,26 +46,6 +70,36 +70,38 +2,55 +20,43 +52,27 +12,36 +4,70 +62,29 +36,4 +55,8 +36,59 +68,3 +12,48 +2,60 +32,64 +46,4 +63,32 +33,60 +28,1 +70,10 +30,66 +23,28 +0,7 +54,44 +57,66 +38,10 +68,20 +2,42 +22,39 +28,70 +12,38 +0,28 +2,62 +19,0 +34,49 +55,48 +41,10 +44,4 +0,43 +16,44 +7,66 +60,50 +2,53 +61,26 +40,46 +6,49 +42,42 +4,54 +47,68 +2,54 +44,51 +4,38 +43,8 +35,4 +64,26 +50,4 +70,4 +60,66 +24,64 +0,35 +8,34 +65,48 +29,54 +10,59 +42,10 +10,34 +16,30 +27,46 +22,67 +32,16 +58,66 +64,40 +52,20 +70,12 +14,70 +1,46 +7,52 +12,62 +28,60 +50,55 +44,64 +62,32 +20,30 +68,6 +23,26 +14,48 +28,37 +6,26 +54,52 +24,55 +33,62 +14,56 +41,4 +48,58 +63,0 +68,18 +52,50 +0,56 +32,18 +7,70 +0,44 +6,64 +40,58 +9,68 +8,20 +9,32 +66,67 +39,6 +3,42 +39,60 +3,64 +20,15 +6,44 +66,1 +6,24 +10,47 +2,28 +50,51 +24,0 +22,34 +0,48 +44,62 +16,58 +14,46 +44,9 +46,2 +30,28 +0,8 +60,58 +40,48 +33,54 +33,18 +35,70 +44,25 +56,27 +38,31 +28,26 +14,52 +41,70 +48,1 +22,24 +39,38 +65,56 +6,6 +54,70 +44,3 +32,54 +24,46 +38,26 +6,10 +54,34 +10,65 +44,11 +30,61 +42,68 +40,68 +54,24 +8,68 +14,4 +40,56 +46,30 +15,0 +16,28 +50,10 +40,26 +6,22 +10,16 +32,28 +66,63 +60,44 +27,54 +8,38 +36,20 +16,14 +8,16 +60,59 +34,68 +55,40 +11,56 +19,34 +4,13 +0,68 +24,26 +22,25 +38,21 +1,40 +27,60 +1,18 +20,48 +32,39 +5,22 +0,38 +55,6 +54,46 +6,4 +9,0 +12,2 +62,52 +56,24 +28,58 +10,22 +49,48 +64,66 +47,0 +22,26 +52,37 +22,40 +15,42 +38,18 +10,53 +27,70 +22,19 +37,16 +15,66 +12,4 +50,30 +30,40 +24,10 +34,7 +26,17 +49,54 +31,28 +29,14 +40,66 +68,16 +42,13 +0,19 +21,40 +21,66 +28,40 +18,56 +49,14 +54,6 +40,0 +34,23 +39,24 +18,4 +70,28 +20,62 +6,60 +67,16 +22,18 +66,52 +15,30 +28,36 +2,14 +61,48 +59,36 +52,30 +36,47 +56,65 +64,67 +58,40 +48,28 +9,42 +36,10 +66,38 +34,50 +8,32 +68,55 +49,66 +40,15 +25,2 +38,29 +62,26 +22,37 +42,26 +4,40 +44,44 +64,64 +4,48 +64,31 +16,62 +1,60 +28,56 +8,26 +24,62 +66,64 +29,28 +38,64 +70,68 +68,0 +49,70 +4,32 +44,12 +33,16 +6,12 +64,34 +68,36 +2,10 +2,33 +52,65 +5,20 +54,57 +56,29 +4,8 +30,19 +40,13 +14,38 +31,30 +49,20 +24,57 +60,8 +35,52 +34,30 +16,70 +68,70 +56,41 +16,42 +66,70 +36,46 +65,58 +3,70 +7,36 +51,70 +12,58 +60,16 +34,36 +27,56 +63,14 +16,38 +60,62 +28,47 +46,8 +49,24 +35,30 +6,37 +62,35 +70,54 +16,34 +26,15 +11,24 +24,39 +23,70 +29,10 +66,25 +10,18 +43,52 +10,45 +56,38 +15,38 +50,38 +24,51 +5,28 +32,45 +30,24 +13,18 +70,24 +40,32 +56,47 +3,66 +16,54 +35,62 +28,31 +19,26 +52,64 +61,70 +58,64 +68,50 +34,20 +69,22 +28,50 +50,58 +61,42 +27,26 +37,10 +42,48 +18,58 +7,24 +41,44 +2,5 +48,48 +56,54 +55,36 +0,13 +45,12 +22,12 +14,16 +24,61 +22,28 +17,22 +62,54 +70,18 +56,9 +18,50 +50,24 +14,68 +53,4 +36,56 +29,26 +6,38 +14,42 +67,64 +64,5 +47,22 +54,16 +68,68 +8,54 +59,24 +12,26 +44,16 +24,54 +22,6 +10,70 +58,10 +47,24 +30,56 +10,40 +36,0 +64,36 +17,24 +17,28 +26,40 +14,3 +70,52 +46,10 +65,16 +32,9 +64,54 +7,62 +68,27 +20,63 +36,24 +33,14 +20,70 +17,34 +56,55 +0,46 +0,10 +48,38 +44,67 +20,37 +47,50 +58,32 +62,66 +40,12 +32,4 +50,42 +42,34 +50,1 +42,6 +24,34 +60,18 +70,59 +42,36 +44,2 +54,56 +38,2 +10,10 +29,44 +43,30 +52,10 +63,46 +42,16 +50,5 +5,56 +59,16 +13,64 +16,39 +64,51 +3,16 +56,4 +35,34 +27,52 +13,40 +21,6 +25,48 +2,16 +6,70 +38,40 +52,66 +61,56 +18,38 +56,32 +0,50 +32,63 +52,56 +58,58 +62,63 +35,64 +56,64 +20,4 +51,40 +11,70 +34,66 +12,40 +2,32 +8,28 +49,68 +70,19 +4,37 +67,14 +2,44 +60,15 +0,58 +44,60 +24,8 +20,51 +14,18 +51,2 +50,13 +62,16 +10,56 +8,24 +55,12 +35,26 +26,68 +12,34 +46,41 +18,61 +30,39 +22,35 +56,5 +24,27 +48,12 +25,20 +6,54 +6,21 +70,1 +14,20 +48,60 +44,43 +18,62 +8,59 +0,11 +10,62 +24,50 +22,68 +24,2 +27,28 +21,68 +36,36 +60,13 +26,29 +54,35 +28,22 +23,44 +57,46 +68,61 +51,0 +40,24 +36,21 +10,8 +20,66 +38,44 +3,0 +58,22 +26,8 +46,12 +58,62 +66,27 +70,35 +44,38 +8,9 +8,48 +48,26 +70,30 +7,42 +25,0 +24,66 +12,32 +42,56 +14,50 +14,64 +44,41 +64,52 +8,66 +40,44 +32,40 +66,14 +68,45 +8,6 +6,59 +8,22 +48,5 +60,38 +13,22 +34,12 +62,13 +35,56 +28,66 +56,36 +32,22 +0,60 +64,6 +48,42 +9,20 +13,6 +55,44 +27,32 +44,28 +11,16 +34,52 +30,10 +4,68 +42,30 +46,70 +43,64 +28,10 +54,54 +66,51 +27,62 +33,64 +38,69 +44,8 +46,46 +58,17 +58,28 +56,40 +33,12 +31,0 +2,30 +44,59 +46,38 +47,10 +22,53 +20,57 +52,26 +24,23 +48,24 +59,56 +70,67 +32,48 +0,39 +14,5 +10,48 +60,23 +67,52 +52,49 +64,16 +36,29 +14,1 +31,20 +35,8 +23,22 +32,58 +16,4 +36,23 +53,54 +8,17 +68,37 +1,12 +64,56 +37,52 +6,46 +36,8 +40,27 +22,4 +28,12 +38,22 +66,35 +4,6 +58,60 +34,0 +22,48 +24,6 +15,62 +62,40 +24,45 +66,66 +1,62 +5,64 +25,46 +54,0 +58,31 +11,30 +4,36 +67,8 +68,57 +62,62 +64,4 +54,8 +60,21 +14,15 +24,56 +8,2 +61,62 +40,2 +69,68 +66,50 +20,59 diff --git a/2024/day18/input.txt.h b/2024/day18/input.txt.h new file mode 100644 index 0000000..f05bed4 --- /dev/null +++ b/2024/day18/input.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_2024_day18_input_txt_start __asm("_binary_2024_day18_input_txt_start"); +extern uint32_t _binary_2024_day18_input_txt_end __asm("_binary_2024_day18_input_txt_end"); +extern uint32_t _binary_2024_day18_input_txt_size __asm("_binary_2024_day18_input_txt_size"); + +#ifdef __cplusplus +} +#endif diff --git a/2024/day18/sample1.txt b/2024/day18/sample1.txt new file mode 100644 index 0000000..79c8583 --- /dev/null +++ b/2024/day18/sample1.txt @@ -0,0 +1,25 @@ +5,4 +4,2 +4,5 +3,0 +2,1 +6,3 +2,4 +1,5 +0,6 +3,3 +2,6 +5,1 +1,2 +5,5 +2,5 +6,5 +1,4 +0,4 +6,4 +1,1 +6,1 +1,0 +0,5 +1,6 +2,0 diff --git a/2024/day18/sample1.txt.h b/2024/day18/sample1.txt.h new file mode 100644 index 0000000..bd4c83c --- /dev/null +++ b/2024/day18/sample1.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_2024_day18_sample1_txt_start __asm("_binary_2024_day18_sample1_txt_start"); +extern uint32_t _binary_2024_day18_sample1_txt_end __asm("_binary_2024_day18_sample1_txt_end"); +extern uint32_t _binary_2024_day18_sample1_txt_size __asm("_binary_2024_day18_sample1_txt_size"); + +#ifdef __cplusplus +} +#endif diff --git a/2024/day18/solution.c b/2024/day18/solution.c new file mode 100644 index 0000000..1a2aa17 --- /dev/null +++ b/2024/day18/solution.c @@ -0,0 +1,141 @@ +#include + +#include "parse.h" +#include "dijkstra.h" +#include "memory.h" +#include "printf.h" + +struct coordinate { + int x; + int y; +}; + +static const char * parse_coordinate(const char * input, struct coordinate * c) +{ + input = parse_base10(input, &c->x); + input = parse_skip(input, ','); + input = parse_base10(input, &c->y); + input = parse_skip(input, '\n'); + return input; +} + +static char map_char(const char c) +{ + if (c == 0) + return '.'; + else if (c == 1) + return '#'; + else + return 'O'; +} + +static void print_map(const char * map, int stride) +{ + for (int y = 0; y < stride; y++) { + for (int x = 0; x < stride; x++) { + + print_char(map_char(map[y * stride + x])); + } + print_char('\n'); + } +} + +int64_t _2024_day18_part1(const char * input, int length) +{ + const char * end = input + length; + + struct coordinate start_c = {0, 0}; + //struct coordinate end_c = {6, 6}; + struct coordinate end_c = {70, 70}; + //int stride = 7; + int stride = 71; + + char map[stride * stride]; + memory_set_char(map, 0, stride * stride); + + int i = 0; + while (input < end) { + if (i >= 1024) + break; + struct coordinate c; + input = parse_coordinate(input, &c); + + map[c.y * stride + c.x] = 1; + i++; + } + + struct dijkstra_xy16 prev[stride * stride]; + int dist[stride * stride]; + int wall = 1; + int turn_cost = 0; + dijkstra_cartesian(map, + stride, + stride, stride, + start_c.x, start_c.y, + end_c.x, end_c.y, + wall, + turn_cost, + prev, + dist); + + /* + int x = end_c.x; + int y = end_c.y; + while (!(x == start_c.x && y == start_c.y)) { + struct dijkstra_xy16 * xy = &prev[y * stride + x]; + map[xy->y * stride + xy->x] = 2; + x = xy->x; + y = xy->y; + } + print_map(map, stride); + */ + + return dist[end_c.y * stride + end_c.x]; +} + +int64_t _2024_day18_part2(const char * input, int length) +{ + const char * end = input + length; + + struct coordinate start_c = {0, 0}; + //struct coordinate end_c = {6, 6}; + struct coordinate end_c = {70, 70}; + //int stride = 7; + int stride = 71; + + char map[stride * stride]; + memory_set_char(map, 0, stride * stride); + + int i = 0; + struct coordinate c; + while (input < end) { + input = parse_coordinate(input, &c); + + map[c.y * stride + c.x] = 1; + i++; + + if (i > 2900) { + printf("%d ", i); + struct dijkstra_xy16 prev[stride * stride]; + int dist[stride * stride]; + int wall = 1; + int turn_cost = 0; + dijkstra_cartesian(map, + stride, + stride, stride, + start_c.x, start_c.y, + end_c.x, end_c.y, + wall, + turn_cost, + prev, + dist); + + if (prev[end_c.y * stride + end_c.x].x == -1) + break; + } + } + + printf("\n%d,%d\n", c.x, c.y); + + return -1; +} diff --git a/dijkstra.c b/dijkstra.c index 0a04ba3..34d9c13 100644 --- a/dijkstra.c +++ b/dijkstra.c @@ -13,6 +13,7 @@ void dijkstra_cartesian(const char * graph, int start_x, int start_y, int end_x, int end_y, char wall, + int turn_cost, struct dijkstra_xy16 * prev, int * dist) { @@ -49,15 +50,8 @@ void dijkstra_cartesian(const char * graph, struct dijkstra_xy16 * xy = &prev[min.y * width + min.x]; int dx = min.x - xy->x; int dy = min.y - xy->y; - if (min.y == 137) { - printf("xy % 2d % 2d pxy % 2d % 2d nxy % 2d % 2d dist %d\n", - min.x, min.y, - xy->x, xy->y, - nx, ny, - dist[min.y * width + min.x]); - } if (cartesian_neighbor[i].x != dx || cartesian_neighbor[i].y != dy) - turn = 1000; + turn = turn_cost; int alt = dist[min.y * width + min.x] + 1 + turn; if (alt < dist[ny * width + nx]) { diff --git a/dijkstra.h b/dijkstra.h index 72035a3..51c5b46 100644 --- a/dijkstra.h +++ b/dijkstra.h @@ -17,6 +17,7 @@ void dijkstra_cartesian(const char * graph, int start_x, int start_y, int end_x, int end_y, char wall, + int turn_cost, struct dijkstra_xy16 * prev, int * dist); diff --git a/input_dreamcast.inc b/input_dreamcast.inc index 00f7988..16ff8f6 100644 --- a/input_dreamcast.inc +++ b/input_dreamcast.inc @@ -46,6 +46,8 @@ #include "2024/day17/sample1.txt.h" #include "2024/day17/sample2.txt.h" #include "2024/day17/input.txt.h" +#include "2024/day18/sample1.txt.h" +#include "2024/day18/input.txt.h" static struct start_size sample[][2] = { { @@ -180,6 +182,12 @@ static struct start_size sample[][2] = { { ( char *)&_binary_2024_day17_sample2_txt_start, (uint32_t)&_binary_2024_day17_sample2_txt_size }, }, + { + { ( char *)&_binary_2024_day18_sample1_txt_start, + (uint32_t)&_binary_2024_day18_sample1_txt_size }, + { ( char *)&_binary_2024_day18_sample1_txt_start, + (uint32_t)&_binary_2024_day18_sample1_txt_size }, + }, }; static struct start_size input[] = { @@ -227,4 +235,6 @@ static struct start_size input[] = { (uint32_t)&_binary_2024_day16_input_txt_size }, { ( char *)&_binary_2024_day17_input_txt_start, (uint32_t)&_binary_2024_day17_input_txt_size }, + { ( char *)&_binary_2024_day18_input_txt_start, + (uint32_t)&_binary_2024_day18_input_txt_size }, }; diff --git a/runner.c b/runner.c index db0b757..941ed9d 100644 --- a/runner.c +++ b/runner.c @@ -38,7 +38,7 @@ bool runner_tick(struct runner_state * runner_state) int year = solution[ix].year; int day = solution[ix].day; - if (year != 2024 || day != 17) { + if (year != 2024 || day != 18) { return false; } diff --git a/runner.inc b/runner.inc index cc592a8..c5cdc4c 100644 --- a/runner.inc +++ b/runner.inc @@ -48,6 +48,8 @@ int64_t _2024_day16_part1(const char * input, int length); int64_t _2024_day16_part2(const char * input, int length); int64_t _2024_day17_part1(const char * input, int length); int64_t _2024_day17_part2(const char * input, int length); +int64_t _2024_day18_part1(const char * input, int length); +int64_t _2024_day18_part2(const char * input, int length); struct day_funcs solution[] = { { @@ -160,4 +162,9 @@ struct day_funcs solution[] = { {_2024_day17_part1, _2024_day17_part2}, NULL, }, + { + 2024, 18, + {_2024_day18_part1, _2024_day18_part2}, + NULL, + }, }; diff --git a/solutions.mk b/solutions.mk index 441c325..ee3dfc1 100644 --- a/solutions.mk +++ b/solutions.mk @@ -70,4 +70,7 @@ DAY_OBJ = \ 2024/day17/sample1.txt.o \ 2024/day17/sample2.txt.o \ 2024/day17/input.txt.o \ - 2024/day17/solution.o + 2024/day17/solution.o \ + 2024/day18/sample1.txt.o \ + 2024/day18/input.txt.o \ + 2024/day18/solution.o diff --git a/test/test_dijkstra.c b/test/test_dijkstra.c index ee180f3..c61d7aa 100644 --- a/test/test_dijkstra.c +++ b/test/test_dijkstra.c @@ -39,12 +39,14 @@ static bool dijkstra_test_0(const char ** scenario) struct dijkstra_xy16 prev[width * height]; int dist[width * height]; + int turn_cost = 100; dijkstra_cartesian(graph, stride, width, height, end_x, end_y, start_x, start_y, '#', + turn_cost, prev, dist);