From 9a3a29d7df6d3fed0f74eadde3a644b3feced43a Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Sun, 4 Dec 2022 06:37:53 -0600 Subject: [PATCH] 2022 Day 4 Complete! --- 2022/day04/input | 1000 ++++++++++++++++++++++++++++++++++++++++++ 2022/day04/main.go | 83 ++++ 2022/day04/problem | 106 +++++ 2022/day04/testinput | 6 + 4 files changed, 1195 insertions(+) create mode 100644 2022/day04/input create mode 100644 2022/day04/main.go create mode 100644 2022/day04/problem create mode 100644 2022/day04/testinput diff --git a/2022/day04/input b/2022/day04/input new file mode 100644 index 0000000..f527fb0 --- /dev/null +++ b/2022/day04/input @@ -0,0 +1,1000 @@ +1-93,2-11 +26-94,26-94 +72-92,48-88 +36-37,37-52 +2-98,1-98 +1-83,1-84 +74-79,76-76 +66-85,66-86 +6-73,6-73 +31-57,30-58 +1-98,1-98 +28-47,55-97 +29-71,70-72 +40-53,40-53 +14-71,39-71 +19-98,18-94 +94-96,81-95 +79-98,79-97 +52-66,60-61 +2-3,8-89 +53-59,59-83 +79-81,3-80 +14-84,84-92 +90-90,7-89 +10-76,11-76 +9-31,10-12 +8-8,8-72 +2-97,1-96 +3-33,2-94 +3-5,4-99 +46-94,8-94 +97-98,14-92 +60-98,81-99 +11-98,11-97 +27-82,26-81 +21-61,12-18 +26-55,26-56 +89-96,97-97 +29-30,29-31 +66-90,40-87 +7-49,8-88 +37-61,39-58 +8-65,9-96 +7-72,2-51 +14-73,15-56 +7-11,16-24 +12-83,13-85 +72-91,7-71 +78-82,56-77 +1-46,15-46 +1-76,1-75 +75-98,5-98 +37-41,22-41 +1-1,2-98 +76-94,77-93 +88-88,4-89 +86-87,38-90 +85-89,46-86 +64-99,1-99 +16-48,32-96 +6-95,6-95 +44-68,43-49 +19-78,19-79 +35-95,7-34 +72-72,32-71 +21-26,24-26 +20-57,21-58 +17-98,17-98 +22-97,21-98 +62-92,92-99 +1-74,1-75 +9-75,10-74 +5-7,4-8 +37-41,4-81 +3-96,4-99 +92-98,94-96 +69-89,75-88 +13-29,14-18 +35-48,42-49 +10-11,11-95 +17-33,32-32 +16-80,61-77 +38-41,40-42 +6-79,6-80 +51-95,50-52 +18-94,19-33 +95-99,15-96 +18-37,19-47 +25-33,24-31 +9-9,10-98 +5-72,6-72 +6-6,7-95 +39-96,38-84 +79-95,57-78 +61-67,61-61 +44-95,9-94 +69-93,16-68 +24-24,23-95 +56-90,49-57 +13-82,13-13 +5-94,4-94 +46-61,44-46 +3-37,7-84 +3-73,3-72 +2-2,3-95 +12-94,24-94 +37-58,37-57 +79-95,7-78 +10-77,76-76 +4-98,5-97 +64-99,27-99 +68-68,69-69 +18-28,18-29 +58-95,9-95 +4-93,5-94 +9-84,85-85 +50-89,51-90 +38-97,2-39 +22-70,78-90 +62-68,67-67 +36-44,36-44 +59-59,36-58 +97-97,1-97 +14-15,15-94 +90-90,3-62 +2-4,3-80 +29-97,81-97 +8-35,34-54 +14-57,14-60 +42-78,10-56 +32-99,31-98 +31-87,86-87 +44-57,44-57 +1-92,92-92 +8-69,5-83 +33-47,34-59 +94-98,11-98 +60-66,67-76 +20-21,21-81 +18-76,17-76 +24-61,24-62 +48-48,1-49 +28-84,85-91 +4-51,4-50 +30-32,31-69 +38-70,39-39 +28-92,37-79 +22-65,22-68 +29-56,9-46 +11-97,2-99 +4-98,31-94 +29-92,29-93 +93-97,32-92 +24-27,25-48 +54-55,6-77 +10-81,82-96 +27-94,28-89 +32-81,47-81 +64-83,65-97 +41-49,50-79 +99-99,14-94 +66-78,66-77 +16-95,17-95 +98-98,3-97 +2-6,6-53 +26-26,12-25 +2-54,3-86 +59-95,94-95 +40-62,2-40 +9-90,9-91 +3-53,2-52 +91-93,88-92 +63-98,64-99 +32-68,68-84 +34-77,74-80 +2-83,1-2 +32-79,60-73 +96-98,3-96 +28-74,29-87 +8-96,29-96 +50-64,50-65 +26-72,15-73 +63-80,44-86 +10-87,11-86 +5-94,36-94 +5-93,6-92 +3-92,4-93 +83-83,14-83 +9-9,9-40 +88-96,12-89 +31-56,34-42 +83-96,28-84 +5-6,6-36 +31-96,30-96 +26-82,41-82 +95-95,18-96 +32-71,31-71 +55-69,56-85 +1-87,2-98 +15-92,9-91 +1-76,1-76 +3-45,3-27 +53-59,52-58 +1-97,5-96 +2-78,4-78 +65-84,84-89 +74-80,79-79 +36-90,37-66 +3-66,54-74 +35-79,35-80 +76-76,75-75 +66-77,65-78 +3-91,3-90 +25-45,26-62 +35-35,36-82 +28-73,29-72 +36-96,37-64 +46-85,85-87 +70-99,2-99 +27-65,36-39 +8-70,70-84 +39-47,38-50 +66-89,23-66 +2-93,5-92 +1-70,92-92 +12-95,15-95 +44-85,45-84 +17-54,17-72 +20-23,19-31 +27-37,14-33 +16-96,82-96 +8-61,7-62 +11-91,73-96 +3-93,40-81 +30-30,29-90 +7-38,38-44 +70-82,12-93 +53-57,54-58 +37-66,66-99 +94-96,11-95 +11-97,11-96 +39-56,40-55 +27-74,1-96 +43-48,3-98 +62-79,63-79 +16-22,24-25 +1-96,2-99 +58-83,57-83 +43-76,42-67 +41-46,8-46 +2-52,2-55 +50-80,28-51 +9-34,9-9 +47-48,46-46 +47-85,85-99 +29-44,29-45 +20-89,19-88 +51-58,60-75 +57-58,57-57 +39-90,38-89 +18-77,20-76 +55-76,54-62 +26-83,25-82 +2-87,2-86 +1-83,2-94 +7-88,88-89 +6-33,7-99 +17-18,10-13 +40-99,40-99 +14-66,31-95 +46-98,46-98 +50-76,73-76 +39-45,2-80 +19-76,18-23 +19-92,98-98 +95-95,1-94 +1-86,87-88 +44-86,45-87 +4-99,4-87 +15-30,14-16 +11-66,13-76 +1-84,14-55 +2-72,2-87 +34-83,77-83 +13-90,30-33 +55-77,49-54 +18-25,7-16 +46-46,47-91 +14-86,14-58 +14-75,79-99 +13-45,14-46 +6-26,7-81 +24-99,35-48 +3-95,94-99 +71-81,20-71 +30-30,31-82 +15-15,14-41 +81-92,82-87 +3-49,48-67 +2-89,2-90 +18-92,19-92 +9-76,8-70 +40-47,41-64 +53-81,81-88 +44-86,44-44 +4-90,98-98 +8-94,95-95 +31-31,32-78 +31-82,30-83 +59-59,40-60 +48-69,48-68 +9-28,28-51 +23-90,23-91 +25-36,57-93 +31-88,30-32 +6-99,4-15 +9-68,28-69 +2-99,3-99 +3-31,30-32 +4-99,4-98 +17-74,11-18 +19-91,19-70 +74-97,75-89 +80-80,33-79 +10-76,2-4 +4-98,18-94 +1-63,1-63 +5-97,5-96 +16-63,16-81 +2-92,91-92 +1-78,79-79 +60-99,35-98 +74-84,39-73 +9-87,9-88 +78-85,77-78 +1-1,1-43 +11-44,12-43 +33-93,9-98 +6-74,5-65 +4-50,4-6 +27-30,25-39 +3-69,39-45 +83-85,86-86 +10-49,50-50 +81-83,8-82 +17-17,18-63 +10-24,20-24 +28-85,86-92 +36-36,37-69 +49-73,46-49 +8-88,7-88 +8-71,9-62 +10-47,46-75 +95-95,92-96 +10-97,7-7 +4-9,3-97 +58-93,43-95 +41-94,40-75 +5-79,3-79 +45-76,46-77 +15-88,7-14 +3-93,3-93 +96-99,4-97 +4-9,6-13 +69-77,5-61 +47-56,71-72 +98-99,15-97 +19-57,53-54 +14-58,37-59 +5-90,22-97 +79-81,63-80 +32-65,33-70 +2-50,50-50 +84-96,7-96 +26-26,27-95 +99-99,2-98 +21-39,21-21 +53-80,54-80 +69-98,59-68 +51-57,57-59 +56-59,29-72 +1-98,2-99 +23-82,34-83 +29-67,30-67 +69-84,85-85 +7-78,78-88 +26-80,81-81 +12-43,12-97 +46-76,45-78 +10-22,9-94 +26-29,25-36 +26-85,26-26 +14-98,15-19 +5-23,9-96 +54-55,55-70 +97-99,2-98 +39-71,3-26 +6-96,6-99 +24-89,62-89 +21-37,37-38 +16-98,15-99 +62-64,2-63 +4-73,4-72 +4-58,6-59 +14-68,14-68 +48-50,49-88 +51-82,45-49 +17-75,4-76 +31-78,78-78 +22-34,14-34 +2-96,1-92 +1-99,98-98 +41-65,64-73 +80-82,17-85 +23-97,22-59 +19-54,16-58 +85-97,47-86 +4-24,23-50 +12-91,90-90 +91-98,91-98 +10-63,9-9 +49-82,48-50 +22-80,23-99 +12-82,13-98 +1-60,2-47 +28-50,19-72 +44-61,44-44 +98-99,66-97 +37-37,37-83 +22-24,23-25 +65-71,65-70 +10-90,89-93 +10-42,42-66 +13-91,90-99 +38-62,48-62 +3-98,4-99 +26-68,27-68 +8-71,82-83 +5-49,50-70 +1-35,1-36 +20-78,79-79 +39-59,39-39 +61-79,61-80 +94-99,95-95 +51-82,83-90 +1-57,2-72 +10-19,11-42 +55-99,54-54 +24-90,89-94 +24-34,34-88 +98-99,45-97 +27-65,2-90 +6-73,5-73 +73-89,72-90 +81-83,78-82 +3-99,3-98 +96-99,52-95 +75-92,6-92 +58-58,12-57 +17-38,37-41 +75-75,5-75 +22-46,22-47 +89-97,2-98 +53-70,19-53 +25-90,89-93 +36-54,46-55 +1-98,97-97 +34-36,2-33 +32-55,31-85 +2-56,56-68 +1-59,1-58 +83-84,1-82 +3-67,4-66 +65-84,41-85 +7-73,16-73 +66-66,23-68 +42-83,42-76 +17-91,17-82 +29-78,29-36 +29-82,29-81 +17-55,54-55 +64-77,63-87 +85-85,45-84 +4-34,3-3 +16-51,52-73 +4-96,39-95 +1-94,31-94 +1-87,2-88 +11-24,12-25 +1-1,3-79 +26-64,13-17 +35-81,54-71 +1-44,1-43 +59-62,22-24 +14-77,8-14 +64-83,83-99 +64-87,87-89 +1-15,15-99 +43-57,48-48 +2-25,2-26 +39-78,39-79 +13-98,14-56 +5-33,75-93 +98-98,3-98 +11-72,10-72 +6-92,5-6 +4-57,4-56 +94-94,40-95 +55-85,55-84 +46-75,45-74 +35-94,34-94 +33-86,85-90 +85-96,42-86 +7-92,5-92 +11-33,10-33 +43-73,38-77 +22-96,1-99 +5-98,4-6 +79-83,78-81 +4-73,32-72 +14-20,20-52 +31-89,30-88 +18-74,9-75 +2-65,2-64 +17-32,33-41 +4-99,8-98 +96-97,77-96 +91-96,63-94 +23-71,52-54 +40-89,49-56 +10-89,10-90 +21-57,21-88 +32-91,33-57 +44-97,44-44 +5-65,4-86 +19-60,18-45 +30-79,80-80 +9-12,8-12 +60-60,59-59 +18-57,48-53 +32-71,72-85 +65-78,35-66 +27-44,41-44 +43-72,14-42 +28-97,28-99 +35-55,35-56 +27-50,1-51 +69-69,51-70 +65-66,5-25 +4-20,3-20 +30-91,31-91 +61-90,61-86 +38-74,98-98 +45-82,78-81 +64-64,5-65 +3-23,2-99 +26-45,2-26 +97-98,19-75 +76-76,5-77 +13-71,12-72 +17-53,52-99 +15-86,87-87 +57-98,23-29 +15-69,9-12 +8-99,18-91 +94-94,19-95 +1-93,93-96 +10-92,52-92 +47-54,70-85 +13-36,12-13 +7-96,15-47 +10-98,11-98 +79-94,89-95 +28-80,80-81 +36-72,37-56 +67-83,67-83 +91-91,80-90 +8-78,1-84 +16-41,40-42 +3-6,5-7 +12-96,8-12 +68-95,95-95 +88-89,16-92 +97-97,43-96 +20-35,34-92 +45-93,46-92 +8-19,9-32 +30-44,13-22 +5-50,6-50 +30-85,84-86 +11-58,57-74 +36-75,7-26 +6-86,3-6 +21-95,94-98 +10-94,14-93 +72-72,7-72 +50-65,51-97 +67-67,68-75 +97-98,10-94 +37-75,33-38 +4-89,4-98 +3-97,2-98 +3-50,47-68 +51-89,52-59 +50-85,84-85 +97-99,29-98 +95-97,35-96 +51-98,99-99 +4-99,75-75 +35-62,5-62 +22-56,21-56 +38-43,49-86 +5-38,5-15 +11-70,6-69 +63-86,28-86 +8-89,10-20 +14-94,4-97 +10-51,10-50 +3-40,4-41 +45-46,46-85 +61-97,62-96 +5-88,5-92 +29-92,91-96 +89-94,3-88 +3-71,2-72 +33-81,34-82 +48-57,47-84 +2-83,48-76 +24-67,24-66 +30-90,30-89 +82-82,58-83 +52-58,52-59 +23-80,8-80 +33-79,34-80 +22-70,23-70 +24-59,25-77 +1-50,8-61 +19-91,91-96 +6-6,7-85 +84-84,81-83 +25-41,16-41 +1-18,2-8 +40-86,78-83 +24-40,41-84 +92-96,3-93 +5-97,2-3 +59-95,94-98 +13-18,13-19 +1-68,5-65 +39-66,66-84 +12-56,8-9 +37-94,38-71 +27-74,27-75 +18-18,19-92 +14-29,14-81 +91-94,11-90 +61-77,3-62 +5-7,6-74 +24-67,23-66 +4-96,4-98 +40-94,41-93 +30-51,52-91 +3-35,1-35 +24-40,39-39 +91-91,76-90 +13-89,14-69 +6-95,7-96 +2-72,1-71 +71-72,72-94 +5-6,6-58 +14-26,28-77 +63-99,57-99 +32-88,4-88 +3-64,63-63 +62-86,85-87 +48-92,24-47 +69-74,62-80 +10-98,53-56 +22-87,1-22 +23-87,92-98 +30-76,31-76 +20-66,21-40 +23-87,87-91 +10-10,11-12 +36-74,75-94 +36-36,10-35 +20-73,14-81 +56-68,55-66 +8-98,7-61 +4-96,4-97 +13-90,1-90 +45-87,45-85 +66-68,24-67 +53-60,39-66 +98-99,2-97 +6-81,80-99 +4-98,4-97 +88-88,14-87 +20-57,21-38 +25-76,24-76 +8-8,10-61 +13-46,13-45 +71-98,70-97 +3-6,9-41 +18-41,40-40 +9-70,21-36 +33-83,11-33 +8-22,80-83 +5-37,6-36 +32-67,67-87 +26-48,25-47 +15-70,69-71 +11-94,15-93 +16-39,16-40 +81-85,81-85 +23-75,23-74 +55-79,55-79 +30-85,29-86 +7-79,78-78 +13-15,7-16 +82-82,29-81 +2-69,15-68 +63-91,52-63 +35-86,87-87 +17-96,18-96 +57-57,58-87 +46-54,46-53 +26-78,27-93 +12-81,12-82 +15-85,5-20 +28-88,36-88 +62-73,63-72 +42-43,17-43 +56-97,56-98 +20-65,17-66 +32-99,33-57 +14-96,15-95 +8-25,7-25 +56-60,56-59 +20-86,19-20 +19-97,20-96 +86-86,58-87 +60-70,59-72 +9-50,32-51 +8-10,14-62 +56-89,88-88 +46-93,92-97 +12-25,1-66 +11-16,18-95 +62-64,17-61 +78-89,43-78 +30-92,30-90 +68-86,69-71 +89-98,33-44 +9-20,8-20 +57-77,16-57 +12-86,11-53 +7-11,28-53 +13-92,14-82 +49-91,92-92 +60-86,60-99 +73-99,73-97 +34-67,54-63 +75-76,43-76 +9-95,94-96 +37-69,38-77 +76-77,45-77 +42-69,42-68 +2-35,2-14 +95-96,15-96 +1-97,2-98 +31-57,31-56 +34-37,33-68 +25-54,24-54 +19-43,9-59 +38-94,93-95 +38-73,38-73 +58-85,58-84 +64-98,58-63 +12-22,12-21 +13-13,14-82 +17-55,17-81 +90-97,88-96 +8-99,47-99 +2-60,35-60 +5-66,6-60 +78-78,4-79 +61-68,48-90 +23-94,93-97 +13-69,12-12 +17-74,1-74 +17-47,48-48 +56-71,70-72 +17-17,17-99 +11-98,12-63 +58-58,58-59 +64-64,65-94 +83-91,1-65 +31-79,78-80 +4-77,78-78 +53-80,3-52 +34-63,62-64 +97-98,1-98 +93-94,41-94 +49-79,50-80 +14-66,14-66 +53-89,45-53 +11-47,10-99 +60-65,61-85 +27-78,26-78 +18-92,19-98 +31-45,17-31 +6-42,5-61 +52-79,51-84 +82-86,83-92 +8-72,71-82 +7-39,6-6 +3-75,75-99 +22-22,22-55 +6-88,6-88 +3-78,34-71 +70-70,11-71 +88-90,52-89 +11-14,28-33 +61-71,50-60 +80-84,7-84 +5-97,98-99 +2-79,3-80 +8-94,8-94 +5-83,83-84 +41-41,10-40 +51-76,13-96 +47-97,48-98 +6-96,7-96 +40-47,41-51 +22-97,22-23 +3-62,3-61 +48-80,43-80 +86-88,8-87 +80-80,52-79 +30-43,29-44 +57-75,56-75 +4-85,3-77 +39-83,38-79 +2-50,1-51 +12-93,11-93 +4-81,3-21 +80-98,79-79 +44-52,51-53 +2-93,92-93 +15-86,2-15 +5-85,5-85 +36-73,36-72 +4-86,3-4 +7-27,8-28 +11-70,69-71 +36-60,37-60 +10-10,16-55 +87-92,88-94 +21-93,20-92 +16-16,15-92 +18-44,19-45 +24-24,24-79 +50-63,15-76 +64-68,65-66 +34-36,30-35 +83-85,2-84 +37-82,37-82 +17-69,17-80 +29-30,30-90 +9-95,9-94 +58-86,58-58 +96-99,17-96 +4-52,12-64 +7-99,8-99 +7-75,7-75 +2-52,26-75 +92-92,9-93 +2-64,3-70 +2-6,5-69 +19-86,9-19 +76-76,7-76 +4-99,1-99 +44-74,2-43 +20-97,79-96 +31-75,31-74 +13-97,13-96 +76-90,90-94 +3-63,4-94 +16-17,17-98 +2-84,84-98 +6-90,5-89 +23-25,24-24 +56-78,78-80 +8-63,7-29 +23-29,23-29 +26-94,25-95 +51-70,51-51 +9-57,14-57 +26-31,25-28 +59-96,59-94 +3-54,1-1 +57-69,31-57 +6-97,5-97 +2-88,55-82 +74-99,73-77 +36-44,36-43 +15-15,2-26 +3-59,4-69 +25-79,26-81 +97-99,59-98 +10-89,74-89 +56-93,92-93 +73-75,18-74 +89-89,12-88 +30-91,31-94 +16-24,15-92 +52-93,51-93 +42-93,41-98 +73-97,21-99 +12-88,87-94 +10-14,10-15 +83-95,53-82 +72-90,68-72 +52-66,14-81 +70-72,11-71 +43-43,13-42 +2-46,2-45 +46-94,76-89 +27-67,9-67 +9-89,28-89 +2-92,92-92 +5-85,86-99 +38-86,12-38 +4-98,3-98 +1-82,6-82 +24-30,24-29 +28-93,27-68 +39-76,5-38 +6-19,5-86 +12-14,13-17 +86-87,29-86 +12-91,12-91 +3-99,3-99 +7-84,6-65 +30-45,31-90 +11-14,21-57 +8-62,61-62 +20-92,20-91 +8-89,8-89 +18-36,6-14 +18-45,17-45 +66-66,5-65 +95-96,11-96 +1-3,4-74 +12-94,94-98 +25-58,25-57 +15-70,15-69 +6-82,1-6 +4-5,5-12 +28-60,59-64 +2-92,92-98 +61-85,86-94 +48-97,39-97 +51-53,42-73 +7-94,93-94 +19-49,15-68 +14-56,3-56 +21-85,20-84 +18-19,19-63 +2-98,3-99 +86-94,73-99 +62-64,4-63 +18-86,19-86 +24-56,25-96 +93-99,16-93 +37-96,36-50 +16-91,15-53 +27-32,28-34 +16-71,15-16 +55-57,56-70 +82-93,70-83 +24-66,24-83 +1-96,2-95 +8-18,9-28 +1-59,1-60 +26-57,11-26 +45-50,46-48 +7-90,8-41 +56-92,57-93 +8-91,8-91 +1-63,6-12 +48-96,96-99 +26-99,26-97 +51-51,52-68 +47-50,6-46 +3-64,13-40 +5-75,3-3 +66-66,9-65 +92-92,7-91 diff --git a/2022/day04/main.go b/2022/day04/main.go new file mode 100644 index 0000000..4370e81 --- /dev/null +++ b/2022/day04/main.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "strings" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + part2(inp) +} + +func part1(inp []string) { + fmt.Println("# Part 1") + var ret int + for _, pair := range inp { + elves := strings.Split(pair, ",") + e1S, e1E := getRange(elves[0]) + e2S, e2E := getRange(elves[1]) + if rangesFullyOverlap(e1S, e1E, e2S, e2E) { + ret++ + } + } + fmt.Printf("Fully Overlapping Ranges: %d\n", ret) +} + +func part2(inp []string) { + fmt.Println("# Part 2") + var ret int + for _, pair := range inp { + elves := strings.Split(pair, ",") + e1S, e1E := getRange(elves[0]) + e2S, e2E := getRange(elves[1]) + if rangesOverlap(e1S, e1E, e2S, e2E) { + ret++ + } + } + fmt.Printf("Overlapping Ranges: %d\n", ret) +} + +func partXAllOverlaps(inp []string) { + fmt.Println("# Part x") + var overlaps int + sections := make(map[int]int) + for _, pair := range inp { + elves := strings.Split(pair, ",") + for elfIdx, elf := range elves { + var overlapped bool + i1, i2 := getRange(elf) + for i := i1; i <= i2; i++ { + if _, ok := sections[i]; ok { + overlapped = true + } else { + sections[i] = elfIdx + } + } + if overlapped { + overlaps++ + } + } + } + fmt.Printf("Overlapping Assignments: %d\n", overlaps) +} + +func rangesFullyOverlap(e1start, e1end, e2start, e2end int) bool { + return (e1start >= e2start && e1end <= e2end) || + (e2start >= e1start && e2end <= e1end) +} +func rangesOverlap(e1start, e1end, e2start, e2end int) bool { + ret := (e1start >= e2start && e1start <= e2end) || + (e1end >= e2start && e1end <= e2end) || + (e2start >= e1start && e2start <= e1end) || + (e2end >= e1start && e2end <= e1end) + return ret +} + +func getRange(elf string) (int, int) { + idxsS := strings.Split(elf, "-") + return h.Atoi(idxsS[0]), h.Atoi(idxsS[1]) +} diff --git a/2022/day04/problem b/2022/day04/problem new file mode 100644 index 0000000..6d085f4 --- /dev/null +++ b/2022/day04/problem @@ -0,0 +1,106 @@ +Advent of Code + +br0xen (AoC++) 7* + +--- Day 4: Camp Cleanup --- + + Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been + assigned the job of cleaning up sections of the camp. Every section has a unique ID number, and each Elf is assigned a + range of section IDs. + + However, as some of the Elves compare their section assignments with each other, they've noticed that many of the + assignments overlap. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a big list + of the section assignments for each pair (your puzzle input). + + For example, consider the following list of section assignment pairs: + + 2-4,6-8 + 2-3,4-5 + 5-7,7-9 + 2-8,3-7 + 6-6,4-6 + 2-6,4-8 + + For the first few pairs, this list means: + + • Within the first pair of Elves, the first Elf was assigned sections 2-4 (sections 2, 3, and 4), while the second Elf + was assigned sections 6-8 (sections 6, 7, 8). + • The Elves in the second pair were each assigned two sections. + • The Elves in the third pair were each assigned three sections: one got sections 5, 6, and 7, while the other also + got 7, plus 8 and 9. + + This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger + numbers. Visually, these pairs of section assignments look like this: + + .234..... 2-4 + .....678. 6-8 + + .23...... 2-3 + ...45.... 4-5 + + ....567.. 5-7 + ......789 7-9 + + .2345678. 2-8 + ..34567.. 3-7 + + .....6... 6-6 + ...456... 4-6 + + .23456... 2-6 + ...45678. 4-8 + + Some of the pairs have noticed that one of their assignments fully contains the other. For example, 2-8 fully contains + 3-7, and 6-6 is fully contained by 4-6. In pairs where one assignment fully contains the other, one Elf in the pair + would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of + reconsideration. In this example, there are 2 such pairs. + + In how many assignment pairs does one range fully contain the other? + + Your puzzle answer was 503. + + The first half of this puzzle is complete! It provides one gold star: * + +--- Part Two --- + + It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would like to know the number of + pairs that overlap at all. + + In the above example, the first two pairs (2-4,6-8 and 2-3,4-5) don't overlap, while the remaining four pairs (5-7,7-9, + 2-8,3-7, 6-6,4-6, and 2-6,4-8) do overlap: + + • 5-7,7-9 overlaps in a single section, 7. + • 2-8,3-7 overlaps all of the sections 3 through 7. + • 6-6,4-6 overlaps in a single section, 6. + • 2-6,4-8 overlaps in sections 4, 5, and 6. + + So, in this example, the number of overlapping assignment pairs is 4. + + In how many assignment pairs do the ranges overlap? + + Your puzzle answer was 827. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should return to your Advent calendar and try another puzzle. + + If you still want to see it, you can get your puzzle input. + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/day/4/input diff --git a/2022/day04/testinput b/2022/day04/testinput new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/2022/day04/testinput @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8