From daeee1aa51737e95e8d5743147d2097d0a769cf5 Mon Sep 17 00:00:00 2001 From: Flxw Date: Sun, 4 Dec 2022 11:06:37 +0100 Subject: [PATCH] feat: day04 part 1 --- day04/input.txt | 1000 +++++++++++++++++++++++++++++++++++++++++++++++ day04/mod.ts | 29 ++ mod.ts | 9 +- 3 files changed, 1037 insertions(+), 1 deletion(-) create mode 100644 day04/input.txt create mode 100644 day04/mod.ts diff --git a/day04/input.txt b/day04/input.txt new file mode 100644 index 0000000..8e62d71 --- /dev/null +++ b/day04/input.txt @@ -0,0 +1,1000 @@ +11-73,29-73 +43-82,44-44 +13-85,12-36 +69-80,5-44 +60-63,30-62 +21-21,21-79 +5-91,92-99 +1-5,4-9 +32-66,23-31 +10-10,10-72 +63-88,62-63 +2-5,4-33 +19-67,72-86 +3-98,2-84 +2-38,32-84 +27-78,69-85 +77-95,78-95 +79-81,22-80 +71-71,39-72 +3-3,7-31 +11-97,12-99 +40-47,40-49 +24-58,57-58 +96-96,9-96 +13-43,14-44 +29-76,94-98 +65-87,51-86 +28-66,28-28 +57-90,58-58 +7-98,8-97 +17-92,18-91 +8-75,3-5 +7-29,6-13 +39-68,55-70 +2-96,2-97 +4-84,5-85 +3-90,65-89 +98-98,1-99 +40-43,19-42 +49-74,19-73 +33-84,3-84 +24-33,7-91 +5-30,6-6 +19-89,20-88 +36-75,74-76 +36-76,75-75 +4-53,27-53 +9-65,8-97 +69-76,41-84 +81-81,53-82 +3-99,3-98 +24-75,25-25 +4-89,1-77 +11-60,11-28 +43-97,98-99 +72-74,4-73 +51-81,56-82 +97-98,1-98 +8-9,9-9 +10-30,30-43 +95-97,71-95 +35-42,32-36 +12-89,11-90 +20-66,20-20 +45-93,94-99 +15-47,15-47 +87-99,13-86 +29-90,56-76 +20-27,20-28 +34-35,3-35 +12-12,12-35 +48-90,47-90 +63-91,92-92 +3-99,2-99 +26-59,26-59 +24-65,24-24 +6-96,6-94 +47-50,48-49 +12-74,11-23 +11-72,73-77 +12-74,11-28 +36-76,37-75 +3-82,2-83 +9-24,8-23 +76-79,67-78 +9-95,10-94 +1-97,4-92 +39-39,11-39 +17-94,17-95 +21-46,20-46 +2-99,3-98 +27-97,26-97 +3-43,34-83 +35-87,36-87 +30-90,31-89 +10-39,3-10 +61-92,15-62 +3-96,2-97 +59-85,86-92 +17-96,9-45 +2-99,3-3 +36-91,35-37 +19-73,20-20 +3-83,2-3 +2-4,3-97 +63-64,63-63 +1-38,2-69 +48-65,57-65 +10-85,10-10 +26-81,26-81 +7-42,43-55 +11-46,10-47 +4-76,5-76 +37-42,33-42 +51-64,52-64 +94-96,17-93 +5-7,6-76 +26-91,25-88 +3-85,1-84 +44-44,43-76 +65-66,66-84 +25-89,33-90 +63-81,14-63 +45-62,45-63 +14-73,14-72 +16-59,59-92 +85-86,83-87 +2-40,23-39 +35-46,35-45 +5-84,6-6 +18-24,18-25 +1-95,54-94 +53-90,52-91 +36-89,90-98 +84-84,69-83 +22-23,23-75 +89-91,86-90 +23-60,18-60 +78-87,87-90 +49-91,40-90 +22-94,26-94 +19-34,20-95 +65-67,12-66 +41-73,42-73 +1-58,3-63 +22-34,7-35 +32-39,31-33 +81-85,39-80 +5-5,4-94 +9-95,10-95 +85-98,31-85 +32-66,33-72 +33-45,33-45 +93-95,14-94 +12-76,9-65 +40-42,11-41 +8-67,9-66 +26-81,26-26 +74-86,95-95 +46-48,46-91 +4-95,2-5 +52-58,51-58 +67-99,21-67 +2-66,2-26 +62-97,61-69 +50-56,50-56 +6-7,7-96 +19-69,99-99 +6-40,6-39 +12-80,8-15 +41-42,41-42 +6-91,5-92 +16-98,97-99 +33-88,34-88 +38-54,10-39 +60-94,8-17 +14-49,50-66 +24-62,61-92 +20-99,11-21 +50-73,50-73 +32-43,6-79 +32-99,10-99 +4-74,11-74 +15-96,16-96 +23-66,67-86 +19-86,18-85 +52-54,53-62 +2-85,1-3 +22-94,21-93 +80-90,43-74 +19-65,20-66 +14-96,15-15 +4-89,20-88 +4-98,32-90 +76-93,25-94 +34-46,19-45 +46-92,58-77 +6-86,85-87 +7-9,8-99 +54-66,54-64 +12-96,97-98 +10-86,44-86 +21-88,21-59 +65-86,64-66 +16-70,17-70 +1-97,2-2 +1-94,5-95 +91-99,4-98 +38-95,37-94 +1-8,8-15 +6-66,3-65 +75-76,13-76 +3-15,14-14 +7-39,7-29 +18-37,16-36 +15-90,14-91 +2-54,2-55 +2-99,3-99 +34-35,31-35 +3-42,41-85 +7-92,6-93 +89-90,61-90 +2-55,14-55 +37-52,38-53 +8-82,7-14 +31-84,22-67 +42-46,42-44 +7-62,6-63 +9-79,9-9 +7-9,8-8 +24-88,24-90 +66-75,75-86 +1-11,2-24 +51-79,4-38 +23-24,23-63 +10-73,11-87 +27-35,34-66 +10-72,7-11 +20-90,17-89 +15-15,15-28 +30-92,21-31 +77-77,15-76 +2-83,72-82 +14-95,15-99 +55-67,54-68 +9-67,8-68 +34-65,34-94 +58-58,57-81 +72-73,29-94 +70-87,22-69 +66-79,8-92 +11-71,12-70 +30-48,29-30 +2-85,2-84 +69-80,13-70 +7-8,7-94 +14-52,14-52 +1-93,62-84 +76-99,12-76 +2-60,53-61 +32-32,32-92 +12-38,1-37 +6-27,7-26 +26-61,2-40 +36-97,37-99 +17-33,18-98 +10-40,3-16 +14-89,15-15 +10-12,11-88 +5-84,8-84 +68-99,68-98 +54-85,2-86 +45-90,10-58 +34-65,35-64 +97-97,20-96 +98-99,1-99 +9-98,9-9 +53-96,54-97 +30-97,96-96 +22-52,51-51 +54-55,54-63 +53-70,52-70 +12-36,23-42 +9-66,46-76 +19-37,20-37 +63-66,63-66 +63-63,62-96 +28-95,9-31 +81-85,85-86 +39-53,39-48 +16-23,2-15 +60-77,22-59 +17-52,18-86 +7-97,40-98 +1-28,5-94 +14-82,13-15 +5-97,4-5 +92-92,34-93 +11-81,80-98 +23-41,22-58 +10-94,21-95 +20-64,21-64 +96-98,2-96 +11-87,11-52 +73-87,88-88 +72-75,6-73 +7-52,52-69 +30-98,31-97 +49-90,26-67 +77-83,62-82 +25-25,26-26 +9-91,10-96 +15-98,15-99 +89-93,9-90 +22-99,16-99 +10-52,11-11 +34-61,34-48 +6-6,5-47 +6-88,7-87 +49-75,49-96 +2-91,3-92 +48-86,93-97 +23-96,9-96 +9-54,10-86 +7-77,8-8 +24-71,24-70 +25-98,26-26 +94-94,51-59 +89-98,36-84 +25-84,83-85 +4-75,5-99 +5-58,2-58 +12-88,11-89 +4-60,56-60 +16-49,10-84 +13-95,4-94 +15-86,16-85 +60-99,59-61 +70-70,15-71 +13-75,12-76 +80-95,79-86 +45-75,44-75 +4-87,4-86 +9-97,10-99 +5-7,6-62 +46-61,60-60 +66-70,65-69 +3-36,16-36 +83-87,36-64 +70-88,72-87 +16-93,92-94 +62-82,81-98 +37-89,88-88 +56-56,7-55 +6-73,8-29 +86-92,85-87 +34-90,91-91 +11-22,21-80 +35-93,55-97 +9-63,62-63 +71-98,30-74 +11-98,7-26 +17-30,31-99 +46-59,62-74 +13-94,94-94 +23-73,34-72 +2-23,2-22 +12-29,12-29 +86-86,31-87 +7-74,7-75 +4-78,78-84 +39-48,40-97 +4-87,5-86 +94-94,90-94 +16-72,16-23 +23-23,23-61 +10-33,13-35 +19-38,30-38 +4-99,1-3 +16-98,15-99 +1-99,98-99 +22-72,22-71 +31-45,32-46 +12-63,12-62 +31-63,64-98 +37-68,9-38 +10-88,8-88 +54-92,73-84 +15-25,15-24 +11-22,11-11 +35-87,10-56 +1-43,3-48 +57-90,56-81 +61-94,94-96 +74-86,18-95 +28-98,97-98 +46-85,45-84 +2-96,6-96 +51-99,50-99 +17-19,10-21 +3-43,3-10 +35-87,35-87 +74-79,75-79 +97-99,22-97 +1-48,5-95 +6-11,12-86 +59-61,59-60 +6-70,3-38 +5-67,4-36 +6-83,2-6 +22-67,40-68 +6-98,7-97 +3-7,2-7 +13-83,12-84 +89-91,49-90 +54-60,53-59 +8-44,12-45 +38-51,35-50 +45-45,15-44 +20-72,71-91 +5-47,5-48 +43-85,44-85 +40-71,88-96 +5-5,4-98 +5-81,5-80 +77-85,77-84 +5-95,6-95 +86-88,58-87 +12-80,11-79 +29-71,29-70 +2-56,4-98 +5-73,74-74 +36-39,5-39 +13-89,12-87 +27-86,26-87 +72-88,18-72 +7-7,6-87 +5-5,4-99 +9-45,9-45 +12-55,13-55 +1-7,3-61 +6-53,6-6 +22-24,21-22 +35-66,65-96 +28-46,5-46 +32-51,31-52 +42-50,51-56 +32-40,31-41 +92-93,15-93 +4-99,1-13 +34-96,7-95 +6-37,6-44 +39-40,4-39 +4-98,3-98 +16-96,16-90 +25-88,24-89 +55-69,23-56 +80-98,79-84 +2-99,1-99 +25-33,32-94 +9-82,10-10 +8-51,50-76 +62-70,63-70 +27-83,26-82 +25-98,25-97 +6-8,7-99 +20-68,21-67 +27-80,27-80 +32-93,26-31 +13-13,13-66 +33-98,33-99 +22-41,68-72 +26-27,10-27 +15-56,15-43 +78-83,82-83 +81-82,41-82 +3-45,2-46 +47-47,47-76 +95-98,62-95 +11-74,11-75 +12-30,31-57 +11-92,93-93 +4-94,11-94 +2-57,1-7 +7-92,96-98 +3-98,1-45 +18-55,37-56 +13-24,14-25 +2-34,35-52 +67-88,68-88 +41-41,30-45 +23-23,26-98 +6-23,2-7 +56-77,7-56 +34-67,30-61 +39-88,40-40 +8-88,8-87 +58-58,32-59 +64-80,79-80 +41-41,41-59 +2-2,2-45 +38-75,70-80 +25-72,25-25 +41-50,36-51 +13-86,14-57 +96-96,56-95 +14-91,13-75 +11-73,74-88 +60-62,61-96 +29-40,28-40 +5-97,6-96 +13-88,13-87 +26-85,27-86 +9-98,2-9 +16-90,17-95 +11-65,9-55 +1-68,2-67 +1-97,96-98 +19-19,19-95 +4-56,5-59 +16-24,23-52 +25-80,24-80 +54-78,36-59 +30-71,72-72 +12-48,7-48 +79-79,80-80 +27-98,26-98 +59-85,30-81 +95-96,94-96 +57-74,57-57 +5-14,6-80 +43-54,47-53 +37-65,37-66 +15-46,46-76 +3-96,2-96 +37-79,38-79 +6-88,5-32 +22-40,22-40 +49-66,18-50 +2-93,2-2 +5-96,5-99 +5-70,3-32 +9-98,7-55 +94-94,19-94 +1-52,1-51 +19-92,91-91 +1-74,5-75 +7-94,95-97 +53-54,49-54 +24-90,6-23 +23-44,43-44 +92-99,68-91 +24-66,23-62 +6-15,6-6 +10-98,3-10 +10-76,9-76 +7-73,31-78 +2-88,2-87 +62-62,25-62 +62-68,52-67 +82-86,82-84 +14-80,12-35 +73-75,47-90 +62-74,35-91 +20-81,20-81 +2-35,3-35 +77-77,8-78 +27-99,68-99 +33-34,34-42 +6-96,7-95 +64-66,22-65 +19-84,20-94 +56-73,56-73 +1-95,95-97 +9-13,13-91 +21-65,58-93 +53-69,53-69 +21-21,20-91 +9-73,9-41 +20-79,21-78 +22-56,57-85 +14-63,13-63 +30-37,37-78 +48-97,62-76 +57-59,58-83 +25-91,26-90 +35-92,35-77 +82-99,9-99 +43-91,44-44 +3-30,2-3 +4-88,4-88 +53-72,60-93 +4-96,3-97 +7-47,35-92 +7-96,95-97 +31-64,12-30 +17-53,52-54 +20-24,19-24 +22-22,21-57 +39-90,38-91 +20-87,5-21 +8-22,22-70 +48-49,2-49 +16-18,17-71 +93-93,29-92 +2-2,3-3 +3-92,4-96 +8-66,61-63 +56-91,37-55 +46-66,46-67 +57-69,68-69 +25-83,24-80 +84-89,66-83 +32-85,32-86 +17-73,17-17 +47-70,48-70 +68-93,58-94 +12-25,9-11 +64-78,77-77 +10-90,90-90 +96-98,19-97 +51-61,54-62 +2-99,2-2 +17-24,23-25 +31-58,59-64 +19-95,95-96 +1-89,88-90 +34-81,17-80 +7-25,7-26 +2-94,1-94 +53-74,11-54 +30-47,13-30 +65-79,79-93 +93-94,94-97 +37-37,36-37 +91-94,95-96 +56-82,55-82 +25-72,24-35 +10-67,10-67 +8-69,8-68 +32-35,34-59 +35-95,34-64 +2-83,1-82 +40-41,33-41 +16-97,16-96 +42-93,94-98 +14-55,55-55 +40-42,41-68 +22-28,3-21 +33-84,44-84 +34-71,9-71 +32-67,32-84 +16-73,68-79 +14-39,14-38 +2-61,4-61 +18-21,20-83 +2-84,7-84 +10-66,67-86 +32-38,32-38 +8-83,82-92 +38-73,37-74 +9-69,10-69 +86-88,8-87 +15-97,14-18 +40-75,39-41 +91-92,66-92 +15-39,92-96 +40-43,42-43 +18-18,17-61 +27-99,28-28 +21-34,30-41 +22-66,65-67 +91-92,66-77 +24-32,4-25 +19-97,14-96 +19-79,80-83 +2-65,5-66 +56-97,41-98 +37-88,38-88 +48-94,48-92 +28-53,85-99 +4-47,4-46 +18-44,17-45 +6-22,7-7 +82-82,28-83 +5-11,13-76 +22-51,21-51 +10-93,10-10 +15-17,16-19 +39-88,23-88 +39-91,16-40 +51-75,50-76 +66-75,74-98 +19-19,18-88 +30-76,8-97 +50-74,51-51 +32-67,37-66 +4-31,13-31 +4-88,3-36 +19-72,77-90 +4-92,3-92 +35-44,36-49 +12-71,70-71 +83-86,46-82 +15-36,3-32 +1-1,1-99 +10-97,96-97 +12-45,13-44 +1-62,1-61 +92-93,5-93 +80-93,54-80 +10-10,12-26 +1-88,1-88 +13-85,43-84 +46-76,46-77 +95-96,6-90 +10-41,10-11 +50-50,35-50 +19-27,26-99 +12-56,11-55 +36-54,10-87 +2-89,2-89 +11-81,10-81 +4-73,5-72 +1-98,1-97 +44-44,45-45 +7-61,8-60 +29-88,26-30 +3-77,4-76 +59-59,58-59 +14-14,13-56 +2-12,1-11 +2-2,1-99 +7-99,8-98 +39-97,39-94 +60-62,16-61 +31-89,44-49 +17-89,18-88 +1-16,4-56 +29-59,28-60 +3-28,27-29 +34-38,37-38 +96-96,2-97 +1-86,86-87 +82-82,16-83 +81-82,38-82 +7-95,2-8 +21-67,8-67 +40-68,18-39 +43-77,26-42 +25-32,25-91 +18-87,18-87 +24-85,25-25 +20-82,20-20 +8-33,32-53 +3-3,2-49 +67-92,54-66 +46-81,45-82 +5-75,4-73 +2-60,11-82 +77-84,57-92 +11-94,11-11 +29-73,51-73 +11-76,77-82 +35-76,19-34 +18-93,19-92 +30-97,30-96 +3-48,21-92 +31-73,32-32 +10-89,7-11 +49-94,17-50 +79-83,10-78 +31-75,1-6 +6-6,6-95 +47-95,48-94 +12-93,67-96 +42-93,36-89 +17-52,27-52 +13-15,14-73 +1-46,1-68 +10-52,24-88 +5-94,5-95 +31-82,69-99 +68-74,30-69 +59-61,29-60 +4-77,4-77 +2-81,11-93 +27-27,27-97 +13-19,19-41 +30-56,57-57 +37-82,38-51 +3-98,3-98 +67-82,48-82 +13-99,13-94 +5-97,5-6 +15-27,28-94 +99-99,1-98 +91-92,4-92 +2-78,3-77 +32-96,34-96 +27-95,26-95 +2-78,2-3 +17-95,28-96 +22-63,62-62 +36-85,35-60 +49-50,46-95 +10-29,11-28 +12-22,1-15 +7-14,6-30 +58-78,78-98 +13-13,12-39 +13-80,14-80 +19-43,18-19 +15-86,13-86 +2-64,1-64 +92-96,41-78 +56-69,56-79 +91-93,45-92 +36-58,19-53 +4-48,10-54 +22-22,23-71 +4-92,25-91 +76-95,51-75 +32-91,31-33 +46-77,46-78 +38-54,53-58 +15-68,14-67 +46-74,67-74 +33-82,32-54 +19-21,20-73 +51-88,31-52 +2-5,6-85 +15-88,15-88 +20-92,20-20 +78-93,79-93 +96-98,57-91 +11-44,6-12 +85-85,56-86 +38-98,38-97 +58-83,57-59 +5-76,75-77 +31-67,66-95 +97-99,1-98 +23-85,22-24 +17-90,16-17 +1-5,4-65 +1-60,1-99 +70-72,71-93 +3-91,14-91 +84-96,3-83 +20-20,20-93 +4-62,4-63 +6-97,3-99 +15-70,15-69 +5-31,30-96 +28-28,28-28 +20-92,19-45 +11-98,11-97 +54-60,53-61 +3-64,1-4 +61-61,17-60 +72-83,73-73 +36-37,37-74 +4-99,7-99 +16-79,7-91 +17-90,18-90 +44-65,6-45 +31-42,31-42 +5-92,91-93 +10-61,53-62 +4-62,1-35 +41-69,68-68 +41-94,41-82 +4-99,3-99 +38-89,33-38 +30-62,30-61 +19-66,65-65 +63-64,50-64 +68-79,42-67 +35-35,36-36 +24-73,74-74 +28-59,60-77 +49-79,3-49 +30-97,31-73 +47-88,28-46 +8-90,9-9 +66-82,11-65 +13-59,12-59 +65-72,31-98 +30-36,35-37 +53-99,99-99 +72-89,73-96 +13-89,14-14 +32-86,6-79 +2-85,1-67 +1-5,1-87 +3-99,95-98 +50-90,49-91 +25-76,26-75 +47-98,48-98 +30-44,31-85 +11-35,11-33 +81-83,57-81 +2-13,12-55 +89-90,21-90 +76-76,76-81 +34-87,35-86 +1-86,1-85 +99-99,20-98 +3-3,3-89 +37-40,41-82 +22-62,61-61 +95-97,4-96 +70-97,98-98 +1-96,1-1 +6-51,7-52 +46-61,24-60 +34-89,8-41 +26-81,25-82 +34-79,34-78 +1-59,2-59 +18-39,17-40 +5-63,5-64 +14-56,56-56 +5-91,5-89 +7-98,8-96 +4-92,2-17 +45-46,1-46 +83-99,81-97 +11-31,11-77 +5-93,6-6 +8-96,97-99 +4-72,18-95 +7-39,38-39 +44-56,45-56 +1-73,1-1 +41-41,20-40 +13-14,14-96 +24-24,25-78 +8-90,8-91 +94-96,8-93 +1-98,4-98 +10-96,9-56 +33-33,33-69 +51-66,51-66 +55-55,54-55 +79-83,59-84 +30-45,45-90 +22-73,21-69 +9-97,96-98 +75-75,34-74 +26-84,26-85 +5-87,4-88 +8-38,9-38 +43-55,14-44 +96-96,11-97 +5-79,4-80 +81-99,43-82 +9-43,42-68 +21-33,32-77 +3-83,5-83 +61-82,43-81 +18-83,19-82 +3-94,4-59 +43-80,5-81 +60-86,86-99 +98-98,56-97 +63-67,63-75 +5-85,9-85 +96-96,35-84 +1-2,2-97 +6-44,43-44 +59-86,85-86 +32-47,31-47 +72-95,73-95 +11-98,98-98 +58-58,18-58 +15-17,16-99 +84-97,50-70 +23-24,24-57 +32-89,14-33 +22-75,20-30 +8-58,7-58 +31-69,35-55 +24-90,89-91 +13-98,14-97 +75-80,74-79 +34-62,33-63 +6-92,6-89 +2-99,1-94 +80-97,42-79 +42-65,50-67 +61-81,78-88 +9-94,10-93 +27-88,27-89 +19-70,20-73 +29-97,28-98 +1-88,3-75 +58-69,38-69 +38-76,37-76 diff --git a/day04/mod.ts b/day04/mod.ts new file mode 100644 index 0000000..e0c74dc --- /dev/null +++ b/day04/mod.ts @@ -0,0 +1,29 @@ +import { readFileLines } from '../utils.ts'; + +export function day04_01() { + const lines = readFileLines('/day04/input.txt'); + let totalOverlaps = 0; + for (const line of lines) { + if (line === '') continue; + const [first, second] = line.split(','); + const [firstLowerBound, firstUpperBound] = first + .split('-') + .map((val) => parseInt(val)); + const [secondLowerBound, secondUpperBound] = second + .split('-') + .map((val) => parseInt(val)); + + if ( + (firstLowerBound <= secondLowerBound && + firstUpperBound >= secondUpperBound) || + (secondLowerBound <= firstLowerBound && + secondUpperBound >= firstUpperBound) + ) { + totalOverlaps++; + } + } + + console.log('1.', totalOverlaps); +} + +export function day04_02() {} diff --git a/mod.ts b/mod.ts index 3a30e40..7954768 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,7 @@ import { day01_01, day01_02 } from './day01/mod.ts'; import { day02_01, day02_02 } from "./day02/mod.ts"; import { day03_01, day03_02 } from "./day03/mod.ts"; +import { day04_01,day04_02 } from "./day04/mod.ts"; // Day01 console.log('Day 01:'); @@ -18,4 +19,10 @@ console.log(); console.log('Day 03:'); day03_01(); day03_02(); -console.log(); \ No newline at end of file +console.log(); + +// Day04 +console.log('Day 04:'); +day04_01(); +day04_02(); +console.log();