From 983d8a70641ae0805c2ed80c541a92b76fdcf638 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 5 Dec 2022 10:26:11 -0500 Subject: [PATCH] Complete day 4 part 1 --- day4/Cargo.lock | 7 + day4/Cargo.toml | 8 + day4/src/input.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++ day4/src/main.rs | 46 ++ 4 files changed, 1061 insertions(+) create mode 100644 day4/Cargo.lock create mode 100644 day4/Cargo.toml create mode 100644 day4/src/input.txt create mode 100644 day4/src/main.rs diff --git a/day4/Cargo.lock b/day4/Cargo.lock new file mode 100644 index 0000000..e92c02c --- /dev/null +++ b/day4/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day4" +version = "0.1.0" diff --git a/day4/Cargo.toml b/day4/Cargo.toml new file mode 100644 index 0000000..8842130 --- /dev/null +++ b/day4/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day4" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day4/src/input.txt b/day4/src/input.txt new file mode 100644 index 0000000..cbdde37 --- /dev/null +++ b/day4/src/input.txt @@ -0,0 +1,1000 @@ +16-80,80-87 +4-9,10-97 +6-94,93-93 +31-73,8-73 +4-72,5-73 +6-63,4-5 +3-44,4-45 +89-96,95-95 +56-95,29-95 +5-22,5-22 +49-63,48-63 +97-97,2-98 +1-13,3-63 +63-93,64-94 +41-63,64-76 +24-45,46-72 +28-94,29-78 +18-36,35-37 +83-85,8-84 +22-35,21-22 +18-48,18-18 +98-98,1-99 +88-94,94-96 +21-93,74-93 +63-83,62-82 +89-90,15-90 +63-80,61-79 +12-14,19-63 +30-30,31-78 +7-88,87-88 +27-41,27-27 +6-35,6-36 +3-78,77-79 +4-67,22-57 +19-82,65-87 +3-93,6-46 +18-30,31-41 +14-95,13-94 +33-59,17-33 +37-38,38-96 +1-5,4-90 +64-79,39-84 +59-62,1-37 +15-29,2-9 +38-44,37-43 +8-75,9-54 +77-89,7-77 +2-87,2-86 +7-81,6-6 +59-94,93-93 +27-75,9-27 +24-76,23-75 +2-10,28-63 +60-61,17-60 +76-76,2-75 +12-60,13-61 +39-96,95-95 +31-88,88-94 +6-79,35-66 +51-93,58-94 +40-74,23-40 +12-62,13-65 +30-49,49-69 +36-98,10-98 +29-95,9-95 +8-79,79-86 +1-73,2-19 +8-15,14-16 +6-34,1-5 +38-58,37-59 +58-84,62-84 +26-26,25-27 +5-89,47-88 +36-50,34-49 +59-94,58-95 +67-71,68-70 +3-64,3-65 +65-93,94-94 +38-91,75-95 +97-97,6-98 +32-78,33-79 +20-89,19-90 +34-95,35-95 +3-99,2-97 +29-90,89-89 +31-48,32-49 +63-81,51-72 +6-96,98-99 +8-94,27-94 +7-99,3-99 +19-90,18-91 +28-97,27-88 +76-86,40-75 +7-65,6-8 +2-12,13-26 +83-88,60-86 +54-99,54-97 +6-7,6-97 +11-78,77-77 +3-99,3-99 +21-21,21-88 +11-20,2-50 +53-88,89-98 +52-97,52-98 +8-29,4-32 +88-89,6-89 +7-62,6-7 +89-98,8-89 +32-91,3-91 +39-49,48-50 +8-63,9-64 +23-80,22-79 +44-66,16-65 +44-58,38-58 +71-98,70-97 +4-99,5-99 +8-90,5-73 +51-98,77-96 +26-89,25-25 +8-25,14-65 +39-64,45-65 +30-94,59-92 +37-96,3-38 +45-72,22-44 +2-95,98-98 +35-35,34-34 +16-82,14-44 +66-79,65-78 +71-72,72-94 +14-21,13-20 +14-92,1-14 +24-69,68-88 +21-80,79-81 +56-86,69-85 +48-85,49-85 +47-90,90-91 +7-22,11-27 +97-98,24-92 +7-91,90-91 +46-58,58-69 +83-92,91-98 +27-66,27-66 +13-92,12-97 +84-86,17-79 +55-91,54-56 +2-87,2-88 +46-46,46-78 +97-97,92-98 +24-47,25-46 +4-22,21-27 +76-87,11-77 +17-87,16-18 +50-81,49-87 +93-98,29-93 +19-44,20-43 +18-53,53-57 +9-45,9-46 +7-55,33-55 +22-25,25-81 +96-96,75-97 +9-11,10-99 +27-73,72-74 +10-72,71-71 +65-66,64-66 +27-81,86-96 +33-37,37-68 +26-90,46-90 +1-4,4-97 +9-95,10-95 +6-32,7-72 +68-89,12-95 +2-98,13-99 +89-91,55-90 +7-23,22-67 +11-11,11-68 +86-90,72-91 +33-53,29-29 +80-91,6-80 +15-87,27-73 +1-99,1-99 +68-69,64-95 +17-62,45-61 +7-26,26-30 +64-96,95-97 +17-18,18-58 +20-97,98-98 +4-87,5-87 +15-19,18-19 +66-67,23-66 +13-95,9-94 +14-81,82-85 +12-85,8-85 +4-91,3-4 +98-99,31-95 +3-77,2-76 +15-97,5-15 +45-72,71-73 +3-70,2-4 +81-97,18-95 +68-83,17-84 +1-3,4-77 +33-92,91-91 +31-91,30-32 +45-64,46-65 +23-94,89-95 +5-76,5-58 +5-86,3-86 +31-69,8-69 +66-69,66-68 +50-64,63-64 +1-97,99-99 +76-77,75-80 +90-97,88-97 +22-52,11-30 +40-70,40-98 +2-96,42-99 +4-49,1-59 +20-75,74-76 +23-52,42-66 +3-94,92-96 +4-93,2-3 +4-92,3-92 +57-75,70-76 +4-95,2-5 +1-41,2-8 +94-99,2-81 +45-63,10-63 +3-8,9-45 +17-50,17-49 +43-76,42-76 +2-86,85-87 +27-29,28-42 +74-80,37-53 +19-97,13-99 +9-31,9-31 +37-39,38-59 +26-79,15-91 +85-85,31-86 +99-99,5-96 +10-39,9-16 +22-60,22-59 +13-95,1-12 +91-93,23-93 +77-98,19-78 +53-93,93-98 +78-80,27-79 +23-25,23-24 +12-62,11-13 +4-48,1-73 +6-63,6-63 +35-86,34-36 +5-27,4-27 +23-73,5-83 +28-34,21-38 +36-93,93-97 +16-84,17-84 +12-99,11-80 +33-81,20-32 +76-93,50-98 +30-82,33-93 +1-99,1-99 +61-68,32-67 +20-84,20-83 +7-13,6-13 +51-52,7-52 +27-67,65-65 +1-91,90-91 +81-98,86-98 +93-97,48-93 +4-53,5-53 +68-76,18-74 +5-21,1-6 +19-97,18-98 +2-65,2-66 +4-72,4-73 +5-92,65-75 +9-77,23-76 +17-89,17-89 +57-60,55-59 +2-90,1-1 +28-81,28-81 +34-56,48-85 +2-97,97-99 +42-43,43-99 +17-60,15-19 +62-99,6-62 +32-41,25-44 +4-37,7-36 +22-72,71-73 +24-32,24-33 +44-78,44-44 +1-32,32-65 +47-95,14-95 +47-77,46-56 +5-97,3-99 +20-99,21-98 +9-65,8-65 +88-96,23-96 +15-64,9-64 +1-24,25-64 +71-91,90-91 +51-52,39-53 +10-57,9-19 +8-86,7-87 +3-7,8-78 +13-17,16-49 +6-90,7-72 +6-86,4-85 +17-93,16-94 +7-83,82-83 +33-81,32-62 +13-99,19-99 +26-98,88-96 +48-98,97-98 +36-50,49-50 +1-75,74-75 +15-95,2-15 +51-58,16-51 +1-98,6-98 +2-99,10-90 +13-97,96-96 +50-70,43-70 +15-33,14-16 +8-89,7-44 +44-91,40-44 +93-94,2-96 +4-88,5-89 +15-73,73-74 +96-97,97-98 +39-57,56-85 +65-67,47-66 +26-27,27-78 +57-80,57-80 +97-99,2-98 +18-18,18-18 +27-47,27-48 +86-93,90-97 +19-47,10-48 +62-78,28-78 +93-99,3-93 +55-59,55-78 +98-99,89-91 +34-35,7-35 +78-88,21-79 +26-92,15-33 +57-64,38-57 +47-92,91-91 +14-38,13-13 +96-99,40-96 +55-84,25-82 +56-76,73-86 +10-82,26-81 +30-89,31-89 +24-68,25-68 +11-44,12-45 +33-49,11-49 +58-58,18-57 +23-84,23-85 +3-31,2-2 +50-96,41-96 +5-98,1-6 +10-97,11-97 +36-91,38-91 +9-88,20-87 +6-96,6-97 +28-87,74-87 +6-77,1-78 +6-73,6-74 +66-93,18-85 +5-80,66-80 +12-95,8-95 +68-89,18-68 +6-15,14-16 +4-87,4-88 +50-50,24-54 +96-97,3-96 +3-46,12-50 +77-87,29-34 +32-53,52-91 +10-68,5-68 +40-54,47-54 +8-22,9-16 +96-99,2-97 +10-63,6-9 +22-65,64-65 +88-89,87-90 +15-99,98-98 +89-89,66-90 +9-65,4-10 +36-61,39-39 +78-99,70-78 +85-87,86-97 +3-73,67-82 +3-68,68-69 +14-15,15-90 +42-59,43-59 +15-60,3-4 +25-92,29-79 +19-99,18-18 +3-88,10-76 +61-98,97-98 +2-92,1-7 +24-86,17-24 +82-82,3-83 +23-25,20-26 +4-65,1-66 +68-72,34-76 +24-93,25-94 +17-47,18-48 +30-65,30-65 +71-77,75-76 +24-64,58-88 +4-30,31-31 +4-65,5-66 +12-65,64-64 +52-52,51-81 +67-69,2-68 +6-81,8-81 +53-88,52-53 +70-98,69-98 +13-15,14-79 +15-71,14-86 +31-65,31-64 +59-86,5-86 +8-9,8-15 +94-96,63-78 +28-49,27-82 +3-3,3-95 +74-74,75-96 +82-96,97-97 +18-83,6-98 +1-74,3-41 +25-87,24-88 +42-96,95-96 +25-89,26-35 +35-61,35-61 +20-39,22-35 +4-65,3-5 +48-97,46-67 +37-73,38-73 +42-45,42-43 +54-85,84-85 +23-61,20-23 +23-60,22-28 +41-63,23-41 +68-90,69-89 +12-97,2-33 +8-83,25-83 +6-12,5-15 +37-67,31-68 +1-2,5-81 +63-89,62-62 +63-90,4-63 +8-95,1-7 +47-72,41-44 +93-94,19-81 +86-88,25-87 +57-57,57-88 +13-94,13-93 +16-17,15-16 +61-80,58-81 +4-96,3-4 +12-28,31-54 +57-96,56-57 +16-89,17-19 +71-87,70-90 +79-93,78-92 +31-38,32-70 +16-17,17-75 +76-92,91-95 +77-77,56-76 +63-90,62-66 +6-86,2-81 +3-42,4-41 +38-94,93-98 +52-60,52-61 +17-84,16-84 +5-5,13-90 +25-25,25-39 +22-91,22-90 +11-76,10-11 +9-45,2-45 +70-77,69-76 +6-10,5-7 +36-36,37-42 +12-96,54-98 +2-96,1-1 +2-94,5-94 +32-84,83-88 +84-84,84-96 +17-54,53-54 +1-68,14-69 +9-98,8-97 +1-88,85-94 +40-69,39-39 +5-21,21-76 +27-28,5-28 +2-80,2-81 +15-96,9-15 +87-89,2-89 +19-84,33-92 +32-95,11-95 +38-53,17-37 +67-89,67-90 +4-5,5-60 +45-84,83-88 +9-32,77-86 +45-72,16-65 +23-24,23-92 +8-93,92-92 +7-91,7-90 +45-48,47-78 +58-58,4-59 +86-91,13-87 +79-85,28-79 +12-13,10-16 +62-99,98-98 +25-96,25-96 +16-57,56-79 +38-77,38-76 +82-97,68-83 +7-66,56-63 +5-7,6-95 +15-93,8-15 +9-93,10-93 +74-90,51-91 +69-75,63-80 +4-11,10-91 +36-99,33-53 +8-8,9-95 +94-96,95-96 +1-38,37-38 +66-77,67-78 +65-87,87-95 +35-37,36-48 +55-92,54-93 +20-21,19-21 +76-76,77-98 +39-69,44-57 +6-26,25-54 +18-37,36-37 +34-74,45-57 +60-83,98-99 +92-94,3-93 +13-59,12-72 +48-98,6-87 +17-88,8-87 +24-92,23-93 +98-98,4-94 +11-57,8-8 +65-87,12-87 +25-99,25-98 +18-88,18-87 +34-80,33-79 +45-96,5-97 +33-67,20-33 +2-98,97-98 +32-33,33-90 +85-90,85-91 +94-94,38-95 +93-93,42-92 +38-48,13-78 +3-95,25-89 +17-93,16-16 +57-70,39-53 +11-61,7-10 +39-89,6-39 +7-17,16-97 +30-95,56-94 +2-8,8-23 +4-17,17-45 +77-82,73-77 +21-84,8-29 +35-91,81-97 +5-54,3-9 +1-94,2-95 +7-66,67-96 +21-45,15-22 +6-45,11-44 +52-87,29-51 +15-82,46-81 +74-76,45-75 +95-99,20-93 +40-89,24-52 +20-99,20-99 +5-34,35-97 +27-45,44-62 +8-75,2-8 +50-55,43-49 +15-50,19-50 +13-71,10-71 +45-64,44-45 +88-92,47-88 +33-68,33-52 +39-79,31-88 +31-58,95-97 +22-31,2-31 +36-88,37-89 +45-93,44-92 +6-97,96-98 +34-72,10-82 +54-58,31-58 +96-98,6-96 +45-46,46-96 +56-69,55-68 +14-54,13-53 +25-45,18-81 +54-55,40-55 +94-98,72-94 +7-91,6-92 +69-96,68-95 +42-82,41-46 +64-94,13-91 +52-80,52-81 +39-69,15-73 +32-53,33-52 +11-22,11-21 +15-79,14-69 +44-65,51-66 +1-32,4-26 +36-36,6-35 +65-71,65-72 +49-74,23-74 +27-96,74-96 +12-70,13-71 +64-66,7-66 +17-97,18-99 +30-30,31-95 +94-96,90-94 +1-15,15-15 +11-45,7-10 +14-93,15-93 +19-47,20-44 +9-97,8-98 +6-62,61-63 +21-51,50-63 +4-95,2-95 +54-55,55-58 +4-62,4-63 +18-88,18-87 +4-79,5-79 +92-97,10-93 +9-79,20-78 +44-87,26-91 +7-51,10-51 +43-92,62-95 +16-44,16-45 +5-98,4-99 +20-64,19-63 +2-20,1-19 +12-96,12-95 +13-94,95-95 +16-46,8-87 +5-24,25-54 +4-12,6-18 +32-66,31-37 +24-76,56-96 +5-51,4-51 +55-60,54-55 +11-74,6-7 +6-99,53-68 +15-90,88-91 +27-84,28-83 +14-67,3-98 +41-56,30-54 +29-52,29-51 +83-89,12-85 +47-76,40-64 +18-70,18-18 +5-20,6-21 +26-53,25-53 +36-48,49-92 +48-80,47-48 +51-63,17-58 +9-79,47-80 +38-39,7-39 +38-58,23-51 +19-37,36-37 +1-61,1-60 +9-65,8-65 +15-17,16-95 +50-66,50-79 +18-39,17-18 +7-14,13-98 +5-80,5-80 +12-98,12-12 +5-6,6-99 +72-91,24-95 +46-92,20-96 +27-73,26-49 +7-52,52-98 +20-57,2-56 +1-69,6-68 +52-95,53-95 +58-71,58-65 +20-86,20-86 +50-71,49-49 +9-79,8-78 +45-62,25-45 +15-23,18-24 +4-96,4-95 +13-97,12-97 +1-99,15-96 +52-54,53-54 +7-10,9-42 +12-79,11-78 +1-88,1-89 +23-95,24-94 +5-96,5-96 +27-73,64-73 +31-97,74-97 +6-74,74-90 +29-91,14-30 +16-36,7-37 +70-83,69-82 +58-96,30-97 +9-89,51-64 +63-88,87-99 +9-22,9-21 +25-99,22-22 +60-60,21-61 +31-83,32-88 +31-65,64-97 +9-9,9-91 +10-47,9-21 +14-97,60-83 +5-74,5-73 +4-7,6-89 +1-94,50-92 +12-69,11-12 +75-84,80-85 +27-38,18-39 +11-27,4-12 +93-96,5-93 +56-88,88-97 +45-99,20-95 +21-93,94-94 +16-96,15-16 +86-92,6-84 +10-63,3-7 +23-59,58-69 +10-13,12-12 +15-97,14-86 +15-98,4-50 +30-30,22-29 +44-58,45-58 +85-87,42-86 +58-59,16-59 +14-63,8-14 +48-64,48-64 +1-34,1-33 +75-99,76-98 +8-60,1-8 +3-8,7-9 +22-70,1-71 +38-93,93-99 +91-93,62-92 +95-95,6-96 +4-92,4-92 +35-99,36-84 +53-94,51-51 +27-93,27-94 +3-5,4-55 +88-94,44-94 +79-95,85-94 +11-23,23-46 +62-88,89-89 +1-84,1-85 +84-86,85-89 +1-99,1-99 +64-81,46-64 +25-26,25-31 +17-92,3-4 +7-51,16-24 +17-97,85-99 +5-5,6-91 +73-91,90-91 +18-65,49-64 +1-93,92-92 +5-97,96-97 +7-14,13-14 +42-73,42-86 +40-48,34-48 +22-94,21-93 +5-71,70-70 +74-92,11-91 +90-92,5-91 +53-58,16-59 +20-78,8-78 +3-5,4-4 +48-50,49-95 +71-88,44-45 +30-39,7-30 +11-69,40-69 +7-85,82-90 +75-79,53-67 +6-84,83-83 +86-95,88-96 +3-46,2-47 +3-86,86-94 +50-98,46-50 +24-45,23-24 +44-52,4-91 +38-67,67-99 +70-93,34-94 +40-86,40-40 +5-71,9-58 +31-71,31-70 +11-50,49-64 +34-39,35-45 +45-72,38-44 +68-73,72-72 +63-64,15-64 +91-91,31-90 +15-86,10-85 +6-17,7-8 +7-96,53-99 +88-88,28-89 +22-65,18-22 +13-95,99-99 +23-99,22-99 +55-62,33-55 +8-85,47-84 +13-81,14-22 +7-90,92-99 +11-47,13-77 +38-64,20-65 +58-61,2-62 +19-27,11-27 +30-43,29-34 +74-95,93-95 +66-76,62-87 +88-88,89-89 +45-80,45-80 +31-76,31-87 +37-84,37-37 +81-81,66-80 +41-85,19-42 +19-47,5-18 +50-75,25-75 +91-92,46-91 +65-84,3-47 +32-34,32-33 +36-60,5-61 +11-98,12-99 +27-74,27-74 +4-41,31-93 +46-76,45-74 +12-38,26-38 +5-80,5-80 +5-99,6-99 +49-90,49-49 +5-85,1-4 +3-99,4-28 +21-39,1-21 +46-86,45-69 +73-92,73-91 +2-97,45-97 +1-81,3-60 +44-78,17-78 +11-78,77-79 +18-51,52-75 +20-82,20-82 +43-55,4-43 +2-33,3-33 +11-16,4-10 +26-34,27-34 +85-94,93-93 +20-30,13-31 +42-90,42-89 +30-45,46-93 +5-99,4-95 +51-51,51-52 +95-96,38-96 +20-72,19-98 +31-86,30-86 +42-82,43-83 +15-89,21-90 +5-98,5-98 +7-96,37-98 +28-29,28-62 +4-89,36-89 +2-98,71-97 +28-90,8-17 +72-73,45-73 +95-96,82-96 +4-60,59-77 +20-63,64-64 +2-24,2-46 +26-67,26-68 +52-53,32-53 +24-99,79-88 +60-62,23-61 +2-96,3-97 +13-92,29-71 +1-2,1-85 +9-77,44-99 +1-96,3-96 +1-68,4-67 +52-60,12-61 +10-90,10-90 +66-69,41-69 +99-99,35-97 +15-95,14-95 +93-95,80-92 +7-41,8-42 +1-94,95-95 +3-32,1-32 +80-83,17-84 +53-69,68-91 +86-90,2-87 +73-87,28-86 +8-35,7-34 +74-88,36-74 +45-45,44-68 +67-88,9-66 +54-90,29-91 +13-45,44-94 +70-71,24-71 +82-96,81-97 +43-73,42-73 +8-45,39-44 +5-42,6-43 +54-93,5-55 +75-96,75-96 +11-31,3-7 +82-90,81-82 +33-77,54-57 +77-79,73-79 +34-90,33-56 +4-13,13-49 +3-19,18-97 +3-97,2-99 +28-51,19-29 +77-78,5-94 +9-11,10-11 +51-69,51-68 +34-73,46-52 +25-96,96-98 +1-55,2-55 +20-81,26-70 +91-97,79-92 +22-74,9-22 +3-97,2-3 +39-94,32-93 +66-95,96-97 +10-10,9-11 +30-65,21-40 +2-94,4-93 +1-91,2-90 +31-84,84-99 +82-95,6-75 +67-91,90-91 +12-12,12-97 +7-75,6-7 +28-28,14-27 +45-50,35-49 +43-72,71-73 +59-73,21-73 +58-75,39-82 +96-97,96-98 +97-97,2-98 +6-92,3-7 +84-86,27-85 +39-95,31-45 +27-84,43-95 +48-95,33-95 +47-55,46-48 +42-82,41-69 +12-96,13-98 +6-99,1-4 +62-94,62-94 +64-82,4-83 +73-75,10-74 +11-24,10-12 +23-54,7-23 +48-53,18-69 +7-11,10-11 +87-87,11-88 +50-79,78-78 +4-52,51-53 +81-82,39-82 +94-97,1-95 +15-75,33-75 +40-52,33-38 +34-71,70-71 +37-38,38-66 +7-43,5-6 +11-20,10-31 +19-98,1-4 +19-87,18-88 +94-95,18-95 +5-13,7-98 +45-73,32-45 +18-95,94-94 +37-95,94-95 +41-42,26-43 +18-92,19-92 +70-90,19-79 +16-95,15-96 diff --git a/day4/src/main.rs b/day4/src/main.rs new file mode 100644 index 0000000..cc8c0e3 --- /dev/null +++ b/day4/src/main.rs @@ -0,0 +1,46 @@ +#[derive(Debug, PartialEq, PartialOrd)] +struct Range { + low: u32, + high: u32, +} + +impl From<&str> for Range { + fn from(s: &str) -> Self { + let parts: Vec<&str> = s.split("-").collect(); + + let low: u32 = parts[0].parse().unwrap(); + let high: u32 = parts[1].parse().unwrap(); + + Range { low, high } + } +} + +impl Range { + fn contains(&self, other: &Range) -> bool { + self.low <= other.low && self.high >= other.high + } +} + +// ---------------------------------------------------------------------------- + +fn parse_ranges(line: &str) -> (Range, Range) { + let ranges: Vec<&str> = line.split(',').collect(); + let range_a = Range::from(ranges[0]); + let range_b = Range::from(ranges[1]); + + (range_a, range_b) +} + +fn main() { + let file_str = include_str!("input.txt"); + + let count = file_str + .lines() + .map(|line| parse_ranges(line)) + .map(|(range_a, range_b)| range_a.contains(&range_b) || range_b.contains(&range_a)) + .filter(|contains| *contains == true) + .collect::>() + .len(); + + println!("Part 1: fully contained pairs: {}", count); +}