diff --git a/18/input.txt b/18/input.txt new file mode 100644 index 0000000..3fd5c91 --- /dev/null +++ b/18/input.txt @@ -0,0 +1,3450 @@ +7,22 +63,47 +4,45 +5,6 +26,3 +1,27 +3,59 +14,7 +37,54 +25,65 +7,17 +69,47 +9,16 +51,61 +61,52 +39,68 +43,62 +47,51 +41,57 +49,60 +12,23 +8,31 +59,58 +67,34 +26,5 +53,65 +16,7 +15,60 +23,31 +3,57 +49,47 +23,67 +57,63 +29,60 +61,43 +41,69 +69,50 +66,49 +29,1 +61,51 +22,3 +6,51 +32,69 +21,9 +46,53 +51,50 +9,32 +22,67 +60,63 +9,22 +15,31 +13,11 +38,61 +18,7 +7,46 +61,53 +21,3 +13,15 +51,65 +1,22 +28,57 +1,3 +65,53 +68,59 +58,61 +51,53 +11,60 +13,23 +61,65 +14,9 +8,37 +3,34 +68,45 +5,25 +41,64 +37,58 +65,45 +67,54 +33,57 +19,7 +56,67 +46,59 +11,34 +11,51 +51,52 +17,23 +21,61 +40,51 +26,67 +13,50 +53,53 +51,47 +65,55 +5,13 +19,9 +47,61 +10,17 +40,61 +57,55 +13,49 +5,63 +2,41 +55,33 +37,57 +69,57 +66,41 +26,65 +33,49 +9,20 +31,65 +27,69 +5,3 +1,19 +15,68 +27,10 +39,66 +48,51 +33,4 +63,65 +13,19 +15,62 +34,59 +67,59 +67,43 +11,25 +15,64 +66,63 +11,61 +14,39 +24,1 +8,7 +31,9 +63,60 +37,53 +65,69 +28,69 +59,61 +2,19 +4,27 +64,41 +55,45 +13,12 +19,15 +23,64 +49,45 +7,41 +29,69 +7,4 +29,58 +12,7 +67,42 +3,50 +41,55 +45,53 +7,31 +55,47 +67,39 +10,31 +9,23 +63,59 +33,66 +7,53 +9,15 +7,7 +70,43 +5,45 +19,2 +21,46 +33,1 +31,57 +7,45 +11,33 +9,31 +55,51 +47,59 +3,26 +52,63 +59,47 +19,67 +27,55 +3,61 +41,61 +32,59 +1,18 +50,63 +7,47 +15,38 +45,54 +48,55 +19,68 +11,5 +57,57 +7,52 +4,41 +11,37 +11,35 +43,61 +63,56 +21,65 +17,5 +62,69 +19,20 +11,8 +69,61 +6,7 +13,62 +63,54 +60,67 +3,12 +29,57 +8,29 +65,58 +49,61 +2,29 +33,52 +57,37 +4,19 +19,11 +9,35 +37,63 +55,34 +11,1 +47,48 +11,28 +56,61 +4,37 +48,59 +31,63 +39,69 +6,25 +4,61 +12,13 +6,59 +69,43 +65,46 +2,61 +69,55 +29,55 +15,22 +9,9 +61,42 +3,43 +4,17 +5,23 +27,63 +63,53 +27,57 +68,47 +14,65 +17,67 +43,66 +59,56 +67,47 +7,25 +27,61 +1,2 +61,57 +63,63 +58,65 +7,56 +37,70 +12,51 +15,45 +0,27 +27,1 +47,66 +5,11 +2,15 +15,2 +5,1 +15,41 +9,50 +1,7 +49,67 +55,55 +2,17 +21,64 +35,57 +12,19 +33,67 +22,13 +9,52 +28,67 +54,45 +18,47 +32,61 +35,50 +10,49 +30,67 +8,19 +3,37 +21,63 +35,69 +1,35 +12,37 +7,1 +5,14 +11,9 +53,45 +67,65 +4,25 +25,7 +11,49 +19,19 +29,3 +51,59 +4,43 +26,9 +13,3 +49,62 +31,52 +59,63 +13,7 +4,51 +13,1 +2,3 +31,1 +15,17 +37,56 +63,55 +61,45 +13,21 +63,43 +2,53 +67,61 +53,61 +31,3 +5,41 +9,17 +13,42 +5,46 +16,47 +17,15 +9,40 +43,69 +5,15 +61,35 +32,55 +11,65 +15,3 +42,49 +57,45 +68,61 +31,54 +1,45 +49,51 +5,57 +28,5 +11,48 +57,64 +38,51 +9,29 +30,61 +13,32 +33,69 +68,41 +35,6 +65,67 +47,49 +45,69 +36,63 +3,5 +7,35 +5,7 +57,61 +38,65 +0,21 +10,47 +33,7 +11,7 +45,43 +17,6 +3,31 +11,47 +41,68 +59,43 +51,55 +69,48 +40,63 +19,69 +67,53 +61,63 +2,25 +52,55 +13,35 +1,41 +13,34 +57,46 +24,5 +21,67 +9,54 +49,49 +3,14 +17,32 +1,47 +49,48 +1,6 +1,23 +65,49 +10,7 +5,37 +31,10 +20,65 +69,66 +52,45 +39,65 +47,53 +69,59 +7,20 +50,49 +10,3 +64,51 +16,3 +29,59 +34,57 +7,40 +3,47 +57,62 +5,19 +3,48 +45,51 +9,42 +8,47 +58,51 +5,30 +4,5 +7,29 +1,29 +0,13 +34,7 +27,5 +21,4 +43,57 +67,38 +23,3 +7,33 +3,39 +61,55 +29,5 +47,43 +69,54 +17,14 +35,61 +58,55 +3,49 +64,57 +59,48 +47,39 +5,33 +7,18 +15,5 +55,67 +45,59 +19,63 +54,51 +67,41 +62,51 +42,63 +33,55 +19,13 +22,17 +34,55 +5,12 +24,65 +17,65 +69,67 +5,27 +23,6 +23,5 +59,57 +30,69 +32,65 +11,27 +59,53 +7,42 +65,51 +9,0 +9,45 +66,69 +51,48 +41,51 +3,35 +6,53 +10,27 +3,33 +19,4 +33,68 +3,10 +51,63 +1,15 +9,53 +14,3 +66,51 +21,1 +3,58 +13,24 +7,19 +31,64 +31,5 +11,11 +20,15 +41,1 +39,57 +5,43 +19,62 +7,13 +61,68 +27,67 +69,52 +47,63 +22,1 +30,55 +3,30 +37,51 +9,27 +7,9 +15,23 +8,55 +29,63 +3,63 +2,39 +17,70 +63,46 +5,40 +15,11 +3,27 +44,51 +53,55 +7,15 +49,59 +41,63 +69,65 +8,27 +13,26 +3,3 +29,64 +64,61 +30,9 +53,62 +7,61 +25,59 +67,69 +3,17 +28,53 +60,55 +53,63 +5,16 +59,67 +55,56 +4,21 +15,67 +41,60 +4,59 +70,45 +3,55 +9,13 +43,63 +45,65 +8,59 +23,8 +63,48 +55,64 +3,1 +32,7 +39,63 +69,49 +3,24 +54,57 +9,37 +25,66 +48,69 +59,49 +4,1 +47,56 +62,59 +21,8 +1,54 +14,23 +56,45 +56,49 +63,49 +19,25 +27,2 +29,62 +41,65 +10,39 +6,43 +61,54 +65,39 +61,46 +51,39 +65,65 +35,55 +22,61 +16,9 +63,51 +1,46 +5,51 +11,26 +13,22 +3,54 +62,49 +13,5 +11,46 +20,67 +63,57 +25,55 +9,44 +19,30 +23,69 +13,31 +53,47 +17,63 +28,7 +16,65 +23,62 +6,9 +5,31 +69,33 +35,60 +68,69 +61,49 +21,19 +29,61 +13,25 +2,49 +7,5 +43,68 +63,41 +3,45 +8,11 +69,69 +32,57 +25,5 +10,25 +5,21 +55,66 +47,57 +3,7 +21,18 +23,65 +13,9 +29,8 +58,45 +61,44 +5,61 +63,44 +33,61 +2,45 +21,6 +5,17 +7,21 +55,48 +39,59 +52,65 +14,51 +5,35 +19,33 +5,39 +8,15 +11,23 +15,63 +47,64 +54,55 +42,55 +59,41 +49,66 +37,55 +8,5 +7,37 +26,57 +58,67 +9,5 +9,24 +28,11 +14,41 +17,17 +15,7 +1,8 +65,62 +46,61 +69,62 +15,30 +62,57 +49,55 +51,54 +1,9 +2,37 +60,59 +11,44 +21,10 +3,15 +55,65 +7,2 +70,37 +55,61 +1,5 +0,49 +29,65 +9,11 +67,44 +29,6 +3,11 +53,58 +53,41 +1,38 +5,47 +21,5 +17,69 +7,39 +54,47 +67,55 +61,66 +53,52 +11,31 +7,27 +9,3 +18,15 +45,58 +10,53 +7,24 +7,55 +37,65 +11,17 +49,68 +58,43 +55,63 +33,59 +59,65 +65,61 +63,64 +6,49 +19,64 +31,61 +3,13 +1,4 +1,49 +23,12 +5,29 +5,49 +54,65 +13,10 +25,69 +3,21 +43,47 +43,65 +41,53 +19,1 +24,3 +32,5 +60,49 +9,57 +39,54 +30,3 +67,63 +5,32 +3,32 +58,47 +65,59 +16,1 +55,53 +39,61 +5,36 +31,69 +20,69 +63,67 +65,47 +17,1 +1,43 +51,51 +14,29 +13,33 +67,45 +17,66 +64,49 +57,41 +25,0 +19,65 +61,64 +57,47 +31,67 +5,54 +68,51 +5,53 +69,53 +1,11 +9,7 +49,65 +66,39 +35,59 +19,18 +56,43 +44,57 +27,7 +24,69 +2,9 +38,63 +13,29 +32,3 +7,36 +57,49 +33,63 +19,10 +57,67 +51,46 +2,11 +11,4 +3,41 +37,60 +68,57 +66,47 +13,6 +26,69 +21,11 +14,31 +57,50 +56,57 +43,59 +65,41 +2,33 +33,12 +2,21 +49,53 +11,41 +35,52 +1,13 +41,59 +29,67 +64,67 +3,23 +62,61 +9,47 +7,38 +25,1 +5,62 +35,51 +65,43 +49,69 +27,3 +6,33 +33,3 +25,67 +17,3 +69,37 +63,70 +7,11 +45,63 +19,5 +11,29 +5,55 +9,51 +49,57 +23,1 +20,61 +65,44 +69,45 +42,59 +1,56 +22,21 +15,48 +47,67 +63,45 +15,61 +47,69 +60,61 +58,59 +1,37 +1,39 +3,51 +11,2 +6,1 +55,59 +7,57 +3,29 +9,49 +7,23 +25,3 +31,55 +17,61 +1,1 +31,0 +57,65 +17,21 +6,29 +12,5 +7,49 +5,10 +15,34 +5,28 +3,6 +12,29 +9,14 +34,63 +51,57 +69,64 +19,39 +32,63 +63,69 +11,45 +9,34 +45,68 +37,61 +13,46 +18,17 +14,17 +7,60 +27,62 +13,47 +13,61 +5,9 +1,36 +59,51 +29,4 +43,70 +7,51 +44,59 +15,15 +57,43 +27,59 +6,17 +13,48 +20,7 +55,69 +7,3 +15,1 +5,4 +57,51 +56,59 +60,51 +21,69 +5,48 +29,56 +61,61 +18,3 +13,45 +48,63 +47,65 +37,59 +55,43 +50,57 +3,53 +5,56 +23,68 +13,41 +66,53 +2,43 +69,63 +18,9 +64,53 +45,62 +8,1 +13,36 +19,61 +27,65 +18,67 +28,65 +45,64 +65,57 +46,69 +36,55 +70,59 +67,49 +54,61 +67,51 +65,68 +20,1 +44,61 +5,59 +7,44 +13,39 +49,52 +18,63 +29,13 +45,66 +29,2 +66,59 +10,37 +26,59 +9,33 +3,56 +1,28 +25,13 +45,67 +9,25 +69,68 +12,53 +12,61 +9,43 +25,12 +15,4 +50,55 +31,58 +7,58 +50,65 +33,15 +11,15 +8,35 +5,34 +31,59 +69,41 +33,9 +61,59 +3,2 +35,62 +1,25 +5,22 +1,44 +47,50 +9,19 +10,21 +62,63 +9,1 +12,41 +63,42 +45,55 +25,14 +3,9 +12,1 +7,8 +15,29 +0,41 +11,18 +15,65 +21,13 +63,39 +9,41 +23,35 +37,66 +61,15 +6,67 +4,67 +23,44 +29,27 +68,27 +21,30 +51,4 +41,47 +63,19 +45,21 +37,43 +23,59 +57,40 +35,44 +23,55 +65,64 +31,31 +57,3 +63,7 +25,17 +18,31 +27,17 +67,22 +39,56 +65,66 +23,23 +52,17 +41,39 +61,12 +17,49 +29,29 +60,29 +29,7 +53,19 +17,36 +15,33 +47,29 +30,39 +11,57 +25,36 +55,54 +38,17 +37,9 +49,4 +13,44 +29,15 +36,13 +16,37 +65,11 +57,5 +21,15 +17,7 +38,19 +13,55 +57,38 +49,10 +23,13 +30,35 +34,69 +27,27 +1,61 +11,21 +1,66 +41,37 +21,49 +37,25 +51,45 +29,39 +33,47 +49,7 +29,42 +31,45 +42,19 +35,9 +41,2 +26,33 +31,41 +16,25 +67,37 +41,18 +40,21 +63,20 +39,47 +59,36 +20,57 +1,65 +5,65 +37,41 +41,40 +26,63 +41,50 +31,39 +46,27 +59,22 +61,17 +29,11 +21,39 +20,33 +52,11 +57,39 +51,15 +59,3 +61,28 +51,37 +59,13 +23,10 +58,7 +53,11 +37,39 +23,41 +35,8 +21,7 +22,23 +67,5 +67,1 +48,35 +29,43 +67,7 +59,2 +23,37 +51,26 +9,12 +13,65 +20,43 +34,33 +11,19 +51,67 +49,5 +63,5 +48,25 +43,33 +35,42 +30,19 +32,27 +46,35 +31,49 +48,39 +11,63 +34,41 +40,37 +7,63 +63,17 +47,23 +11,40 +53,44 +33,36 +35,63 +68,31 +35,25 +65,25 +15,9 +20,25 +36,19 +63,13 +39,7 +62,39 +19,38 +25,51 +49,23 +33,42 +61,47 +65,37 +51,27 +44,31 +27,47 +45,23 +67,57 +67,56 +28,13 +25,28 +70,33 +43,19 +25,15 +47,10 +25,23 +42,43 +52,61 +1,68 +48,19 +9,21 +67,24 +15,59 +3,64 +27,23 +9,69 +28,35 +55,5 +47,45 +28,31 +29,41 +21,29 +37,33 +42,21 +3,19 +27,29 +15,21 +64,11 +63,61 +25,8 +60,43 +66,11 +27,45 +3,69 +5,67 +50,23 +41,32 +45,61 +39,53 +65,26 +15,39 +55,8 +21,47 +6,13 +66,25 +15,50 +51,11 +25,9 +43,28 +35,36 +37,23 +18,23 +44,49 +43,1 +31,53 +51,6 +63,30 +53,37 +69,2 +48,31 +52,23 +15,52 +67,33 +17,33 +50,19 +52,35 +47,17 +57,15 +43,5 +59,59 +21,59 +37,24 +51,5 +33,24 +55,11 +39,6 +15,51 +62,19 +56,29 +67,3 +7,67 +53,30 +43,39 +22,25 +51,33 +62,35 +26,23 +65,63 +51,23 +15,53 +15,26 +47,19 +21,35 +57,28 +1,60 +69,18 +11,53 +35,34 +32,49 +18,21 +1,67 +67,25 +57,10 +55,37 +25,18 +0,59 +59,17 +41,21 +63,4 +39,24 +55,16 +61,67 +55,14 +17,53 +15,37 +62,23 +38,41 +50,27 +70,13 +32,31 +45,29 +61,19 +55,2 +39,38 +43,24 +47,20 +50,11 +25,41 +47,18 +42,7 +24,55 +38,49 +53,24 +63,23 +24,29 +23,29 +19,53 +45,1 +29,19 +17,29 +28,41 +43,43 +31,7 +69,15 +61,27 +38,33 +57,7 +57,35 +23,21 +37,31 +57,13 +37,30 +39,4 +63,11 +67,13 +41,23 +50,39 +55,9 +1,21 +23,7 +45,28 +14,15 +26,41 +29,47 +43,15 +51,28 +31,43 +31,17 +29,37 +39,11 +49,8 +23,9 +55,25 +41,17 +60,9 +37,49 +19,41 +53,23 +34,13 +35,3 +21,56 +41,35 +17,57 +33,21 +35,23 +23,26 +35,11 +48,41 +49,2 +59,4 +45,9 +37,37 +59,15 +19,58 +35,27 +67,66 +11,43 +63,31 +49,24 +59,16 +29,49 +35,21 +67,19 +17,13 +18,53 +39,26 +20,13 +37,15 +17,59 +3,25 +60,31 +35,19 +26,39 +59,38 +25,63 +69,11 +53,57 +43,49 +11,59 +17,45 +65,29 +20,21 +57,17 +53,68 +1,57 +35,26 +26,47 +68,37 +31,40 +13,17 +53,31 +36,37 +65,5 +40,19 +55,57 +4,69 +15,47 +5,5 +66,55 +36,5 +59,23 +64,19 +69,51 +36,53 +56,37 +47,1 +42,15 +67,12 +9,60 +45,3 +19,26 +17,19 +24,23 +9,61 +57,4 +18,43 +24,53 +43,36 +21,55 +52,37 +35,31 +57,27 +63,37 +55,39 +38,1 +32,37 +40,5 +45,42 +69,23 +31,35 +65,1 +35,47 +55,15 +13,20 +41,49 +29,16 +53,43 +26,55 +67,17 +44,33 +56,13 +21,51 +36,17 +23,20 +29,18 +34,27 +51,18 +33,65 +38,9 +48,15 +58,35 +16,29 +35,39 +43,46 +49,33 +19,40 +65,15 +36,11 +47,0 +39,32 +47,22 +36,31 +23,34 +45,17 +45,39 +63,38 +53,7 +46,5 +27,53 +59,55 +69,5 +45,5 +55,29 +47,37 +51,69 +47,25 +67,21 +33,27 +43,17 +69,7 +35,24 +37,7 +49,3 +27,11 +59,12 +46,3 +53,67 +31,26 +48,29 +29,25 +37,44 +51,17 +29,48 +36,21 +13,13 +51,29 +9,39 +57,29 +43,55 +31,13 +59,5 +34,1 +41,43 +31,27 +67,27 +55,21 +25,57 +1,55 +38,11 +67,31 +50,7 +31,33 +19,23 +39,44 +43,30 +52,7 +42,37 +31,25 +23,57 +20,37 +31,29 +39,46 +23,11 +66,7 +55,6 +61,26 +13,63 +7,43 +46,33 +32,17 +35,46 +43,22 +41,7 +53,12 +45,20 +13,57 +61,29 +17,24 +64,23 +7,64 +57,1 +21,37 +30,31 +53,29 +47,2 +49,30 +56,69 +51,35 +55,20 +19,21 +19,29 +61,14 +55,31 +39,16 +53,9 +47,3 +44,13 +21,38 +33,8 +33,31 +33,29 +59,26 +50,15 +19,31 +21,60 +35,7 +29,51 +52,15 +46,47 +67,30 +15,27 +65,20 +45,37 +27,15 +31,21 +49,46 +17,54 +59,69 +19,35 +23,45 +55,27 +27,37 +59,27 +49,38 +17,47 +29,46 +25,45 +21,21 +59,33 +61,33 +61,39 +25,37 +65,18 +22,39 +55,32 +43,4 +43,26 +45,35 +67,29 +41,41 +16,21 +25,22 +2,69 +25,44 +55,18 +32,29 +63,14 +40,15 +69,24 +43,31 +53,50 +61,41 +51,3 +59,18 +39,39 +23,15 +33,17 +26,49 +21,17 +41,66 +35,43 +27,43 +35,18 +37,19 +33,11 +44,1 +24,31 +47,8 +48,45 +68,39 +65,3 +61,2 +27,24 +62,37 +37,5 +33,25 +49,35 +69,3 +27,52 +8,67 +41,67 +37,69 +65,17 +63,24 +41,46 +37,29 +69,8 +10,11 +63,35 +25,21 +55,3 +49,13 +20,47 +17,25 +63,16 +22,57 +57,59 +47,35 +37,47 +34,39 +47,11 +41,25 +37,3 +49,29 +53,32 +37,1 +43,45 +59,20 +16,11 +31,51 +45,25 +15,54 +38,13 +28,21 +69,1 +38,29 +51,31 +9,59 +39,43 +16,57 +0,31 +11,13 +26,35 +7,69 +43,67 +25,29 +35,15 +23,46 +31,44 +68,35 +17,27 +9,64 +18,39 +45,19 +37,8 +42,1 +13,43 +32,47 +51,36 +17,56 +2,65 +57,23 +61,13 +35,41 +57,30 +30,13 +55,0 +46,41 +35,35 +37,45 +18,55 +58,11 +45,26 +51,13 +37,13 +21,43 +31,47 +55,17 +34,15 +61,10 +55,40 +27,31 +25,39 +61,21 +28,27 +41,26 +52,9 +25,33 +44,9 +69,6 +41,34 +19,49 +38,21 +35,66 +56,23 +49,9 +36,49 +28,37 +53,38 +47,44 +67,11 +33,5 +47,31 +6,69 +51,60 +17,39 +14,59 +55,41 +39,51 +39,5 +15,35 +13,59 +67,0 +39,33 +56,33 +23,58 +51,42 +47,55 +63,25 +37,21 +45,57 +61,7 +46,17 +20,23 +62,5 +21,31 +63,3 +62,1 +69,13 +9,65 +25,53 +66,3 +65,27 +45,41 +39,21 +38,5 +45,14 +21,42 +5,66 +47,47 +61,1 +11,68 +61,3 +27,41 +19,37 +65,21 +35,48 +19,17 +27,54 +43,6 +37,17 +1,52 +18,35 +24,43 +61,18 +53,27 +35,22 +38,35 +13,69 +21,23 +47,14 +66,17 +23,39 +67,23 +44,37 +39,19 +27,60 +29,50 +43,27 +56,1 +15,43 +49,19 +42,53 +61,9 +25,35 +57,20 +49,16 +43,7 +27,19 +27,42 +18,49 +23,49 +59,29 +30,51 +1,51 +43,16 +45,27 +1,69 +37,42 +59,14 +53,66 +59,1 +57,69 +34,3 +19,51 +33,33 +24,25 +53,13 +53,28 +43,25 +15,58 +55,42 +15,25 +25,19 +43,42 +43,53 +53,49 +40,13 +23,56 +46,55 +43,41 +15,44 +31,28 +54,69 +39,3 +13,53 +29,31 +65,13 +57,53 +67,15 +21,33 +33,41 +27,38 +43,3 +29,24 +47,12 +14,55 +52,41 +19,32 +62,9 +64,33 +26,11 +53,3 +26,15 +13,51 +11,58 +35,33 +31,22 +34,51 +3,67 +39,17 +16,41 +51,25 +13,67 +41,31 +23,48 +65,7 +32,41 +19,57 +33,18 +39,67 +67,35 +11,14 +45,49 +25,31 +43,35 +64,29 +39,27 +49,21 +9,66 +63,33 +58,33 +62,31 +60,17 +19,52 +34,47 +29,9 +41,29 +34,29 +25,52 +51,20 +19,3 +21,53 +62,7 +55,24 +35,49 +37,67 +19,47 +37,11 +57,33 +51,68 +36,1 +61,37 +46,39 +16,43 +16,51 +54,5 +45,11 +51,58 +60,33 +51,49 +65,32 +11,64 +37,35 +59,19 +39,15 +22,31 +7,59 +16,19 +23,19 +24,49 +57,19 +68,21 +21,45 +55,36 +25,25 +54,35 +62,27 +32,1 +40,29 +11,70 +33,37 +23,63 +54,9 +43,34 +23,43 +67,4 +25,20 +32,33 +13,37 +16,45 +42,13 +49,25 +23,51 +65,9 +17,60 +21,36 +53,2 +63,32 +65,31 +32,15 +25,47 +11,55 +55,22 +53,33 +23,61 +42,39 +26,17 +57,22 +52,31 +45,16 +49,31 +1,17 +41,8 +44,53 +49,1 +18,59 +35,67 +43,9 +9,10 +39,45 +55,19 +61,69 +57,42 +53,15 +45,45 +67,32 +54,41 +20,51 +38,37 +14,37 +63,21 +51,70 +39,48 +22,41 +68,15 +39,23 +15,69 +11,3 +19,55 +25,49 +45,47 +29,32 +39,9 +29,23 +21,27 +39,25 +53,69 +43,13 +69,10 +45,7 +17,55 +33,51 +53,5 +59,8 +51,7 +58,25 +41,3 +55,26 +41,27 +30,25 +59,37 +53,17 +29,17 +53,59 +34,21 +51,21 +41,9 +1,63 +66,29 +32,45 +17,51 +11,56 +31,23 +19,46 +68,13 +45,24 +35,17 +55,1 +28,15 +53,51 +53,4 +39,37 +17,43 +63,29 +59,25 +40,9 +70,17 +70,25 +49,17 +24,33 +19,45 +36,27 +25,61 +67,67 +38,23 +35,13 +17,9 +33,19 +22,33 +27,49 +56,53 +26,27 +21,54 +27,44 +29,22 +9,62 +59,35 +30,43 +33,45 +69,20 +18,27 +41,11 +49,11 +0,63 +21,41 +41,44 +23,47 +30,15 +37,46 +43,21 +24,59 +24,17 +21,57 +11,32 +65,22 +1,33 +39,41 +25,27 +1,53 +43,56 +49,34 +21,28 +58,3 +34,31 +27,26 +52,1 +13,16 +17,41 +69,39 +69,29 +40,57 +15,12 +59,40 +66,9 +29,34 +69,21 +7,65 +43,51 +41,5 +49,27 +23,53 +55,12 +53,22 +27,50 +68,5 +55,7 +45,8 +61,22 +27,9 +53,39 +35,37 +65,19 +45,22 +53,35 +19,27 +69,28 +57,26 +53,1 +65,2 +46,31 +27,39 +60,35 +41,13 +19,43 +27,21 +58,53 +61,0 +51,19 +23,33 +40,59 +44,19 +12,57 +27,18 +45,31 +13,66 +9,68 +45,15 +29,35 +33,35 +17,37 +36,35 +65,35 +39,30 +57,18 +24,41 +19,50 +13,27 +47,13 +35,68 +61,25 +6,63 +47,27 +46,37 +47,9 +49,32 +64,3 +47,21 +9,63 +43,23 +54,29 +33,13 +39,31 +59,70 +27,33 +39,55 +29,45 +19,59 +59,24 +37,27 +68,1 +25,43 +58,31 +31,12 +40,35 +22,53 +57,31 +65,33 +1,31 +57,25 +53,26 +40,23 +39,1 +39,49 +43,2 +28,47 +64,27 +15,14 +35,1 +63,27 +33,39 +16,33 +63,10 +15,13 +31,11 +31,15 +44,45 +15,55 +39,29 +49,39 +49,36 +27,13 +59,9 +42,31 +33,38 +69,17 +55,35 +39,35 +59,39 +26,31 +44,5 +39,13 +36,3 +23,17 +29,21 +55,23 +24,39 +69,9 +10,63 +47,15 +65,23 +48,5 +53,20 +38,27 +65,36 +44,47 +55,13 +4,63 +61,23 +63,15 +10,57 +33,20 +31,20 +11,39 +33,53 +41,45 +67,18 +22,35 +51,9 +1,59 +27,25 +67,9 +49,43 +49,37 +50,3 +15,57 +59,31 +27,35 +69,35 +24,37 +23,25 +45,40 +67,64 +27,51 +53,21 +64,5 +17,40 +66,35 +17,35 +45,50 +54,17 +31,37 +66,13 +17,12 +49,12 +35,53 +41,28 +33,23 +27,20 +13,68 +28,29 +49,22 +47,41 +56,5 +39,2 +64,15 +40,53 +59,11 +62,15 +17,28 +51,41 +11,67 +67,16 +41,48 +37,68 +31,34 +61,5 +43,37 +21,44 +66,27 +47,7 +51,34 +30,37 +3,65 +53,48 +12,65 +5,69 +15,19 +22,51 +57,9 +21,25 +45,33 +36,39 +44,39 +22,15 +47,33 +35,10 +29,33 +23,50 +59,7 +50,41 +49,15 +63,9 +47,5 +57,21 +11,69 +69,19 +37,40 +29,53 +17,31 +35,29 +60,5 +14,69 +65,8 +57,11 +25,11 +23,27 +55,49 +15,18 +69,25 +40,41 +51,43 +64,7 +21,48 +30,49 +48,43 +53,25 +61,11 +33,10 +35,65 +58,15 +43,11 +51,1 +45,44 +24,15 +43,29 +12,55 +19,12 +51,14 +35,5 +45,13 +40,11 +41,15 +45,12 +25,62 +9,67 +31,19 +63,40 +27,30 +37,14 +49,63 +43,10 +46,7 +41,33 +17,11 +69,27 +60,39 +59,21 +19,16 +12,11 +61,31 +50,29 +68,9 +15,49 +49,41 +20,27 +35,45 +47,26 +39,52 +42,11 +59,45 +54,11 +33,43 +32,23 +56,9 +63,1 +35,16 +27,46 +9,55 +63,34 +41,19 +69,31 +2,68 +31,32 +50,67 +19,44 +25,64 +64,22 +14,12 +19,48 +54,36 +21,58 +30,2 +50,22 +67,58 +22,56 +2,46 +63,8 +2,55 +58,10 +41,62 +62,2 +62,17 +4,29 +30,58 +4,49 +56,62 +42,70 +42,0 +70,57 +46,64 +48,37 +18,57 +41,10 +41,16 +22,64 +20,30 +6,23 +40,24 +53,16 +64,65 +12,44 +5,8 +58,29 +23,60 +36,69 +40,22 +32,2 +46,65 +28,30 +19,24 +26,20 +28,48 +27,58 +4,46 +31,62 +15,28 +29,28 +8,32 +33,28 +58,68 +1,24 +44,17 +58,60 +66,16 +4,62 +4,30 +40,33 +16,59 +38,48 +6,27 +36,14 +35,32 +20,24 +30,62 +18,52 +55,10 +32,62 +64,54 +62,25 +4,53 +36,28 +52,4 +31,70 +62,38 +11,52 +20,0 +18,2 +23,70 +60,66 +16,56 +31,60 +46,12 +6,64 +38,10 +4,50 +8,62 +50,45 +58,13 +44,67 +35,30 +29,12 +68,33 +19,56 +29,38 +6,50 +38,46 +20,68 +57,68 +66,31 +29,54 +37,2 +49,40 +20,44 +32,58 +6,61 +6,19 +50,20 +32,8 +62,20 +64,16 +6,66 +14,49 +56,19 +56,64 +26,66 +17,46 +38,22 +56,41 +11,50 +32,52 +42,25 +29,30 +31,66 +64,25 +10,45 +69,4 +28,66 +24,67 +12,16 +14,60 +31,68 +36,46 +14,32 +34,44 +54,10 +48,9 +54,37 +68,16 +19,42 +16,0 +42,33 +30,60 +41,22 +60,2 +44,32 +65,6 +16,14 +26,61 +52,69 +62,24 +47,38 +45,10 +44,4 +42,36 +28,59 +30,10 +26,68 +17,10 +50,5 +41,52 +36,44 +36,9 +17,50 +8,53 +30,32 +44,35 +33,2 +15,0 +22,28 +60,69 +42,14 +26,25 +10,48 +46,9 +16,18 +67,70 +20,35 +4,20 +7,30 +30,45 +4,66 +26,62 +21,32 +20,28 +46,6 +61,16 +20,39 +66,20 +6,22 +70,22 +64,36 +26,24 +70,14 +24,28 +0,68 +40,28 +51,62 +22,26 +19,60 +47,68 +3,60 +54,64 +0,70 +66,67 +51,8 +4,26 +20,32 +52,64 +22,55 +48,14 +56,6 +70,34 +62,29 +52,18 +68,24 +63,0 +17,34 +18,68 +53,6 +26,64 +70,31 +50,66 +16,64 +4,58 +40,32 +48,65 +32,39 +58,63 +14,68 +60,14 +60,22 +8,50 +16,42 +2,31 +60,15 +52,70 +2,18 +50,16 +26,12 +12,34 +62,12 +34,46 +1,42 +62,4 +30,66 +35,14 +29,36 +50,0 +60,21 +54,24 +50,47 +34,52 +38,8 +54,22 +51,2 +6,45 +38,59 +46,40 +58,22 +63,6 +54,70 +16,30 +19,34 +66,66 +0,69 +39,36 +6,21 +37,22 +54,56 +64,26 +49,44 +50,12 +70,19 +38,15 +21,0 +27,32 +3,40 +0,44 +2,52 +16,54 +34,38 +48,24 +16,39 +26,53 +2,27 +68,36 +10,26 +6,24 +24,13 +35,70 +30,0 +52,13 +64,69 +54,19 +28,24 +64,28 +34,49 +6,55 +44,60 +2,54 +5,64 +14,22 +28,40 +34,62 +28,58 +30,47 +20,38 +10,62 +60,68 +8,0 +22,34 +24,30 +13,52 +22,70 +27,48 +3,20 +40,8 +67,28 +12,60 +36,56 +22,27 +20,26 +22,43 +24,44 +58,4 +33,62 +44,66 +20,48 +48,67 +28,55 +24,62 +30,40 +18,48 +17,42 +41,12 +28,54 +4,56 +6,58 +48,34 +60,24 +46,8 +8,21 +50,38 +70,27 +33,32 +17,48 +8,43 +50,18 +47,70 +12,62 +17,68 +35,56 +33,30 +66,15 +25,30 +10,12 +16,35 +46,4 +54,6 +11,12 +22,60 +32,9 +60,6 +42,67 +67,6 +26,6 +14,56 +18,26 +32,43 +70,10 +47,6 +12,32 +18,1 +15,42 +32,48 +2,51 +45,70 +10,33 +26,42 +31,42 +4,42 +32,53 +59,64 +18,36 +59,62 +68,14 +28,60 +20,31 +54,62 +10,35 +64,38 +28,63 +62,67 +64,0 +10,58 +46,36 +5,0 +36,15 +10,68 +32,44 +12,12 +20,34 +33,44 +39,42 +19,36 +58,62 +1,62 +15,32 +14,35 +50,36 +54,68 +14,38 +47,24 +56,60 +64,18 +60,16 +69,0 +53,70 +28,50 +34,5 +66,6 +32,54 +42,69 +6,60 +57,66 +4,22 +0,20 +14,46 +17,18 +37,16 +34,66 +33,6 +41,0 +60,30 +33,64 +41,30 +43,50 +50,61 +8,63 +52,32 +44,69 +23,0 +6,6 +46,46 +3,46 +31,18 +58,40 +14,20 +8,51 +40,64 +20,10 +66,70 +63,12 +41,4 +49,18 +43,8 +60,18 +36,33 +42,51 +50,25 +62,21 +57,24 +10,32 +45,6 +2,42 +52,26 +46,19 +32,64 +38,43 +38,64 +19,14 +28,9 +0,7 +70,49 +36,57 +14,24 +14,40 +63,18 +0,18 +54,26 +18,69 +56,31 +52,50 +12,50 +66,28 +20,63 +4,39 +12,21 +60,44 +34,70 +69,14 +64,50 +4,12 +32,6 +48,68 +6,41 +14,14 +52,59 +40,20 +1,10 +2,2 +34,30 +65,34 +9,70 +24,4 +54,60 +18,16 +19,70 +35,12 +39,8 +14,5 +30,20 +48,36 +52,40 +24,22 +36,2 +64,37 +53,46 +60,28 +17,52 +32,10 +56,47 +9,58 +8,46 +53,0 +20,22 +37,48 +17,58 +60,38 +62,55 +6,16 +0,66 +66,58 +20,4 +60,62 +42,48 +46,60 +43,54 +42,17 +24,70 +0,1 +40,58 +24,2 +26,18 +30,59 +18,38 +38,62 +5,70 +23,42 +24,8 +4,48 +55,52 +70,0 +7,28 +25,26 +66,43 +40,69 +21,2 +58,70 +6,4 +47,4 +56,38 +10,46 +58,23 +47,30 +41,42 +39,14 +44,8 +25,58 +29,44 +36,38 +22,32 +8,26 +47,42 +16,58 +47,36 +50,14 +35,2 +13,30 +31,46 +60,10 +55,60 +54,46 +46,18 +28,68 +28,32 +54,32 +16,32 +40,44 +32,30 +10,59 +44,30 +58,18 +24,27 +12,25 +56,42 +11,6 +1,14 +30,18 +0,10 +12,0 +36,34 +22,38 +64,8 +7,10 +4,57 +39,18 +51,44 +5,50 +53,18 +43,44 +66,60 +60,8 +32,14 +14,70 +62,60 +36,43 +64,1 +0,56 +48,49 +2,26 +14,47 +2,20 +42,3 +12,43 +57,48 +15,36 +61,40 +40,42 +29,20 +70,63 +42,35 +51,16 +54,44 +46,63 +66,30 +56,46 +0,42 +38,47 +19,66 +16,15 +44,18 +28,1 +49,58 +16,49 +30,5 +56,50 +18,60 +64,35 +2,66 +48,38 +34,6 +58,16 +56,26 +28,38 +6,20 +65,40 +16,38 +6,39 +40,52 +38,36 +0,55 +52,27 +30,54 +62,34 +61,58 +65,10 +50,53 +50,28 +10,70 +4,38 +63,66 +25,50 +60,58 +46,15 +41,36 +26,8 +7,34 +53,14 +52,60 +50,35 +5,44 +16,34 +16,46 +70,8 +56,39 +14,44 +39,64 +70,38 +0,4 +22,52 +20,29 +66,12 +31,8 +30,44 +60,25 +36,67 +50,24 +17,30 +54,50 +56,0 +25,42 +24,18 +14,66 +53,8 +62,3 +39,28 +9,30 +2,67 +12,31 +0,38 +56,3 +56,55 +12,49 +68,28 +64,21 +38,20 +70,9 +21,24 +60,41 +6,57 +65,28 +54,14 +51,0 +0,67 +64,24 +44,43 +25,38 +20,45 +2,7 +44,12 +50,13 +13,58 +43,38 +54,25 +7,48 +48,3 +56,17 +1,34 +31,48 +10,64 +56,27 +38,39 +38,32 +42,58 +68,52 +68,34 +60,56 +36,64 +2,6 +18,61 +64,48 +34,58 +48,1 +70,3 +62,6 +64,43 +6,47 +7,68 +51,66 +36,59 +70,11 +49,28 +2,44 +45,56 +55,44 +57,70 +56,52 +27,28 +16,40 +52,5 +56,34 +69,26 +6,36 +69,60 +52,52 +34,14 +15,24 +24,47 +44,58 +44,64 +54,27 +70,7 +8,57 +33,14 +63,22 +60,7 +44,23 +53,60 +28,39 +30,22 +9,28 +67,20 +1,50 +38,30 +40,36 +3,42 +59,68 +57,8 +56,63 +44,56 +58,5 +18,20 +68,19 +62,56 +40,60 +52,57 +60,57 +44,63 +44,29 +58,41 +60,0 +60,70 +24,34 +56,12 +63,36 +46,34 +4,47 +63,58 +16,36 +58,27 +8,4 +28,17 +48,53 +42,34 +66,19 +70,56 +16,22 +18,65 +25,56 +58,32 +12,54 +64,59 +13,56 +58,26 +50,2 +31,38 +66,8 +41,70 +42,18 +6,8 +18,19 +64,32 +28,51 +24,68 +40,65 +60,23 +48,23 +24,9 +7,62 +47,52 +11,16 +22,22 +30,53 +26,21 +31,30 +66,54 +46,14 +38,38 +24,54 +3,44 +60,50 +4,64 +23,4 +24,10 +19,22 +55,70 +49,26 +36,45 +70,30 +48,42 +4,34 +48,62 +23,40 +59,0 +0,62 +30,63 +24,14 +21,34 +28,33 +18,8 +24,6 +14,62 +59,54 +1,30 +40,26 +45,32 +55,46 +64,46 +61,50 +37,12 +10,14 +62,47 +10,10 +30,7 +48,18 +56,58 +20,42 +13,8 +7,6 +12,3 +61,24 +8,61 +45,46 +16,31 +2,36 +68,67 +26,13 +38,28 +46,67 +27,16 +48,27 +56,54 +11,22 +68,43 +10,42 +45,30 +8,48 +56,48 +48,46 +39,70 +8,44 +32,21 +0,14 +3,4 +48,58 +35,0 +14,53 +14,8 +64,47 +22,54 +27,0 +4,31 +61,8 +5,52 +64,64 +28,4 +48,56 +54,3 +45,18 +59,28 +42,62 +11,62 +28,26 +40,17 +62,18 +6,14 +62,30 +62,16 +28,64 +55,50 +24,26 +26,60 +30,8 +30,16 +57,0 +40,0 +62,40 +48,44 +19,0 +66,18 +38,54 +56,24 +24,46 +26,0 +6,44 +28,6 +36,66 +44,6 +10,40 +18,37 +44,7 +59,34 +8,64 +59,30 +65,54 +50,42 +22,65 +4,23 +22,58 +52,10 +33,46 +30,30 +61,30 +38,58 +20,40 +22,66 +68,25 +4,6 +70,41 +22,37 \ No newline at end of file diff --git a/18/main.go b/18/main.go new file mode 100644 index 0000000..d6e77fb --- /dev/null +++ b/18/main.go @@ -0,0 +1,230 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" + "time" +) + +const FILE_PATH = "./input.txt" +const SIZE = 71 +const BYTES = 1024 + +//const FILE_PATH = "./sample.txt" +//const SIZE = 7 +//const BYTES = 12 + +func LoadInput(filename string) ([]string, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + var lines []string + scanner := bufio.NewScanner(file) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + + if err := scanner.Err(); err != nil { + return nil, err + } + + return lines, nil +} + +type Vector2 struct { + x int + y int +} + +type structuredInput = []Vector2 + +func TransformInput(lines []string) structuredInput { + var result = make([]Vector2, len(lines)) + var numbs []string + var x int + var y int + + for i, line := range lines { + numbs = strings.Split(line, ",") + x, _ = strconv.Atoi(numbs[0]) + y, _ = strconv.Atoi(numbs[1]) + result[i] = Vector2{x, y} + } + + return result +} + +const ( + EMPTY = iota + WALL = iota +) + +func generateGrid(size int, bytes int, memory []Vector2) [][]int { + var result = make([][]int, size) + + for i := 0; i < size; i++ { + result[i] = make([]int, size) + for j := 0; j < size; j++ { + result[i][j] = EMPTY + } + } + + for i := 0; i < bytes; i++ { + result[memory[i].y][memory[i].x] = WALL + } + + return result +} + +func printField(field [][]int) { + for y := 0; y < len(field); y++ { + for x := 0; x < len(field[y]); x++ { + if field[y][x] == EMPTY { + fmt.Print(".") + } else { + fmt.Print("#") + } + } + fmt.Println() + } +} + +var MOVEMENT = []Vector2{ + {1, 0}, + {0, 1}, + {-1, 0}, + {0, -1}, +} + +func add(a Vector2, b Vector2) Vector2 { + return Vector2{a.x + b.x, a.y + b.y} +} + +func isInBounds(position Vector2, bounds Vector2) bool { + return position.x >= 0 && position.x < bounds.x && position.y >= 0 && position.y < bounds.y +} + +func Part1(input structuredInput) int { + var result = 0 + + var start = Vector2{0, 0} + var end = Vector2{SIZE - 1, SIZE - 1} + var field = generateGrid(SIZE, BYTES, input) + var bounds = Vector2{SIZE, SIZE} + var score = make([][]int, SIZE) + var poss = []Vector2{start} + var point Vector2 + var index int + var temp Vector2 + + for i := 0; i < SIZE; i++ { + score[i] = make([]int, SIZE) + for j := 0; j < SIZE; j++ { + score[i][j] = -1 + } + } + score[start.y][start.x] = 0 + + for len(poss) > 0 { + point = poss[0] + index = 0 + for i := 1; i < len(poss); i++ { + if score[point.y][point.x] > score[poss[i].y][poss[i].x] { + point = poss[i] + index = i + } + } + + if point == end { + result = score[end.y][end.x] + break + } + + poss = append(poss[:index], poss[index+1:]...) + for i := 0; i < len(MOVEMENT); i++ { + temp = add(point, MOVEMENT[i]) + if isInBounds(temp, bounds) && score[temp.y][temp.x] == -1 && field[temp.y][temp.x] != WALL { + score[temp.y][temp.x] = score[point.y][point.x] + 1 + poss = append(poss, temp) + } + } + } + + return result +} + +func canFinish(field [][]int, start Vector2, finish Vector2, bounds Vector2) bool { + var visited = make([][]bool, len(field)) + + for i := 0; i < len(visited); i++ { + visited[i] = make([]bool, len(field[i])) + } + var poss = []Vector2{start} + var point Vector2 + var temp Vector2 + + for len(poss) > 0 { + point = poss[0] + poss = poss[1:] + for i := 0; i < 4; i++ { + temp = add(point, MOVEMENT[i]) + if isInBounds(temp, bounds) && !visited[temp.y][temp.x] && field[temp.y][temp.x] != WALL { + poss = append(poss, temp) + visited[temp.y][temp.x] = true + if temp == finish { + return true + } + } + } + } + return false +} + +func Part2(input structuredInput) int { + var result = 0 + + var start = Vector2{0, 0} + var end = Vector2{SIZE - 1, SIZE - 1} + var field = generateGrid(SIZE, BYTES, input) + var bounds = Vector2{SIZE, SIZE} + i := BYTES + + for canFinish(field, start, end, bounds) { + field[input[i].y][input[i].x] = WALL + i++ + } + i -= 1 + + fmt.Printf("%d,%d\n", input[i].x, input[i].y) + + return result +} + +func main() { + var start time.Time + var elapsed time.Duration = 0 + input, err := LoadInput(FILE_PATH) + if err != nil { + fmt.Println("Error loading input:", err) + return + } + + structuredInput := TransformInput(input) + fmt.Println("Structured Input:", structuredInput) + + start = time.Now() + fmt.Println("Solution Part 1: ", Part1(structuredInput)) + elapsed = time.Since(start) + fmt.Printf("Part 1 took %s\n", elapsed) + + start = time.Now() + fmt.Println("Solution Part 2: ", Part2(structuredInput)) + elapsed = time.Since(start) + fmt.Printf("Part 2 took %s\n", elapsed) +} diff --git a/18/sample.txt b/18/sample.txt new file mode 100644 index 0000000..0371b23 --- /dev/null +++ b/18/sample.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 \ No newline at end of file