From 9aee75494d8d2f025b193dfd582c2adca1a08e98 Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 4 Dec 2022 10:08:26 +0200 Subject: day 4 --- Advent-of-Code-2022/aoc-4/build.sh | 5 + Advent-of-Code-2022/aoc-4/input.txt | 1000 ++++++++++++++++++++++++++++++++++ Advent-of-Code-2022/aoc-4/main.c | 76 +++ Advent-of-Code-2022/aoc-4/sample.txt | 6 + 4 files changed, 1087 insertions(+) create mode 100755 Advent-of-Code-2022/aoc-4/build.sh create mode 100644 Advent-of-Code-2022/aoc-4/input.txt create mode 100644 Advent-of-Code-2022/aoc-4/main.c create mode 100644 Advent-of-Code-2022/aoc-4/sample.txt (limited to 'Advent-of-Code-2022/aoc-4') diff --git a/Advent-of-Code-2022/aoc-4/build.sh b/Advent-of-Code-2022/aoc-4/build.sh new file mode 100755 index 0000000..30f495e --- /dev/null +++ b/Advent-of-Code-2022/aoc-4/build.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -xe + +gcc -o main main.c -Wall -Wextra -pedantic diff --git a/Advent-of-Code-2022/aoc-4/input.txt b/Advent-of-Code-2022/aoc-4/input.txt new file mode 100644 index 0000000..7775d82 --- /dev/null +++ b/Advent-of-Code-2022/aoc-4/input.txt @@ -0,0 +1,1000 @@ +18-20,19-21 +9-86,9-87 +7-8,8-18 +82-98,98-99 +17-17,17-77 +13-21,20-79 +46-52,45-46 +34-54,37-53 +4-91,3-5 +9-80,5-83 +66-83,67-83 +1-5,1-1 +24-27,23-23 +3-91,5-90 +20-81,19-20 +93-99,15-94 +1-86,1-87 +95-99,16-96 +5-94,93-94 +93-95,61-94 +2-87,2-86 +11-97,11-96 +2-49,50-78 +54-59,2-55 +7-96,8-97 +28-29,29-93 +8-86,8-55 +38-54,38-64 +97-97,44-96 +20-88,21-89 +57-80,58-80 +34-39,32-35 +7-73,8-73 +40-62,39-62 +50-52,51-51 +25-79,24-26 +13-84,12-85 +47-83,47-84 +49-77,76-77 +11-53,30-52 +85-86,86-86 +61-78,46-79 +19-52,20-92 +10-66,65-66 +90-92,13-91 +49-88,87-88 +44-79,45-80 +34-57,34-58 +68-70,52-69 +2-5,6-85 +19-74,18-75 +12-99,12-96 +95-95,45-96 +27-74,23-26 +86-90,88-88 +39-96,40-97 +42-49,43-55 +23-42,5-75 +3-86,1-93 +3-24,25-36 +76-80,8-76 +26-38,25-97 +27-39,16-38 +33-77,34-77 +64-81,13-63 +3-4,4-98 +52-80,42-51 +90-91,16-96 +16-56,45-47 +30-99,1-31 +51-96,10-51 +44-82,44-81 +3-53,2-64 +51-71,19-67 +5-80,80-96 +59-61,60-98 +84-84,77-85 +23-78,22-78 +43-84,14-82 +67-92,66-68 +10-98,23-96 +33-57,33-41 +20-72,19-71 +33-98,21-34 +32-55,55-97 +7-88,5-96 +28-76,3-28 +13-39,12-38 +19-26,30-71 +24-99,83-83 +90-96,66-76 +5-10,11-96 +10-92,15-90 +25-89,39-90 +13-97,12-97 +3-97,98-99 +4-6,5-97 +15-33,32-33 +4-42,10-71 +22-93,92-94 +22-84,7-16 +29-34,26-35 +11-66,11-85 +6-38,1-7 +47-93,5-92 +2-97,97-99 +6-55,54-86 +24-90,89-90 +10-79,10-57 +58-59,59-60 +44-55,45-56 +4-88,4-87 +99-99,2-96 +4-40,41-66 +86-92,15-85 +50-82,81-92 +4-77,5-78 +2-98,97-98 +4-34,35-35 +12-52,22-36 +46-47,46-47 +17-89,14-97 +52-66,65-66 +43-51,51-88 +26-68,27-68 +67-99,3-66 +38-92,93-95 +94-94,6-70 +7-93,29-95 +3-88,1-4 +82-83,68-83 +45-74,31-74 +2-95,37-94 +26-93,69-88 +81-82,74-82 +1-35,36-64 +3-70,4-70 +84-90,83-89 +48-65,23-48 +32-76,31-76 +30-86,31-85 +3-6,1-3 +49-80,49-79 +47-88,48-88 +2-13,3-14 +41-73,40-74 +67-92,67-88 +10-85,9-85 +14-87,13-87 +15-23,15-24 +35-56,57-73 +48-78,47-85 +13-99,6-13 +7-9,7-12 +3-85,13-51 +17-42,18-43 +24-68,23-47 +18-71,17-71 +5-33,4-4 +21-22,22-96 +16-83,82-97 +1-15,14-16 +2-2,2-2 +4-50,3-4 +73-97,73-98 +4-95,4-59 +18-62,18-99 +74-80,73-80 +2-62,3-43 +3-75,1-18 +72-74,21-73 +6-98,6-99 +3-98,1-3 +7-73,6-74 +7-77,6-77 +10-69,10-34 +21-92,20-93 +54-60,99-99 +9-83,1-3 +16-17,17-59 +5-81,3-96 +39-81,40-81 +57-87,3-86 +42-95,94-95 +53-60,51-61 +25-25,23-24 +12-66,11-67 +27-54,27-88 +14-30,30-92 +41-48,40-48 +27-58,42-59 +2-12,13-46 +53-54,18-53 +59-61,60-60 +21-80,2-84 +2-37,36-87 +14-85,13-86 +9-38,8-8 +83-97,99-99 +3-90,94-98 +17-97,16-16 +15-18,16-19 +13-90,13-89 +60-91,60-91 +47-85,86-91 +65-72,4-66 +4-44,45-82 +97-98,9-98 +18-97,18-47 +24-49,14-64 +38-85,37-97 +40-90,35-56 +23-91,6-99 +19-97,29-97 +9-90,8-89 +96-98,44-81 +48-59,37-59 +60-75,26-59 +30-99,30-79 +13-45,12-12 +9-24,25-94 +30-61,16-51 +56-97,56-80 +1-55,4-93 +3-99,12-94 +32-74,32-32 +31-35,20-34 +61-90,61-88 +20-57,56-91 +1-93,5-92 +1-94,1-95 +8-93,3-7 +10-12,13-55 +15-30,31-85 +81-84,82-85 +59-75,58-75 +6-78,77-79 +17-26,17-35 +34-67,66-67 +47-53,54-54 +22-98,23-98 +74-89,51-80 +47-59,45-47 +95-96,11-96 +1-47,1-37 +86-87,87-87 +32-32,32-33 +77-84,55-98 +85-85,12-85 +39-79,39-78 +61-88,11-61 +58-59,59-91 +82-90,5-90 +2-99,1-99 +17-96,64-96 +31-89,88-90 +81-83,6-82 +52-80,27-51 +59-68,60-67 +67-69,68-91 +17-87,18-87 +22-99,11-92 +3-98,4-98 +76-94,95-96 +63-99,64-72 +14-19,19-22 +67-68,67-69 +29-97,29-98 +2-51,1-3 +3-83,1-86 +3-64,4-39 +6-53,52-98 +67-69,22-69 +84-88,5-87 +23-28,28-82 +21-96,12-98 +24-91,90-95 +19-94,2-98 +29-91,30-86 +15-98,14-99 +12-47,20-66 +11-86,12-87 +66-90,39-66 +77-94,65-94 +63-81,64-81 +5-67,6-82 +47-49,44-48 +52-93,94-94 +53-86,25-87 +27-27,17-72 +26-94,40-77 +27-27,12-26 +17-90,18-91 +33-78,77-79 +79-97,96-99 +67-68,52-68 +5-63,1-6 +20-34,10-35 +54-81,82-82 +28-99,29-98 +9-89,91-94 +6-94,5-94 +37-40,19-41 +52-77,14-77 +35-45,48-99 +21-66,53-65 +30-33,29-29 +12-72,3-84 +62-84,19-58 +34-54,81-83 +20-98,21-93 +7-72,19-93 +88-90,12-89 +2-48,2-23 +4-94,3-93 +38-58,14-39 +85-86,53-86 +10-78,1-11 +30-30,31-60 +38-91,32-82 +83-85,82-84 +40-82,82-83 +24-29,19-74 +24-70,25-69 +56-69,56-71 +32-84,26-85 +3-98,97-99 +11-90,10-89 +48-75,49-75 +17-95,18-45 +31-79,72-74 +4-4,5-89 +76-91,57-77 +9-80,88-89 +61-91,60-91 +35-86,35-85 +56-66,57-67 +58-69,55-58 +65-90,43-66 +47-72,46-48 +7-14,5-6 +92-97,36-90 +11-49,11-64 +32-44,43-45 +18-74,19-75 +68-82,31-56 +62-90,59-91 +21-93,93-98 +13-18,17-61 +7-94,7-8 +7-10,10-71 +1-92,2-92 +9-12,15-70 +31-56,14-49 +14-93,15-90 +56-79,6-57 +7-96,6-28 +13-96,8-45 +24-44,43-44 +13-77,68-77 +28-96,28-97 +15-96,92-94 +7-43,7-42 +23-40,23-26 +58-96,59-96 +76-76,75-96 +30-56,29-31 +80-97,79-96 +21-49,21-48 +3-75,23-75 +4-6,7-96 +56-91,7-55 +2-14,15-70 +35-62,27-34 +64-93,63-63 +10-10,11-18 +1-69,1-70 +97-98,1-98 +50-92,31-91 +12-12,13-59 +89-92,14-90 +14-15,14-15 +81-85,4-99 +20-84,13-89 +19-32,32-72 +35-39,37-40 +32-64,33-64 +39-67,68-75 +47-55,46-48 +36-67,35-67 +4-20,3-19 +33-70,52-69 +1-98,3-96 +17-74,16-74 +83-98,84-97 +12-36,12-29 +68-84,1-17 +15-63,14-63 +55-56,13-63 +9-62,61-63 +11-36,5-12 +23-81,4-85 +18-78,77-78 +4-95,3-97 +42-75,42-64 +7-97,5-7 +17-90,16-16 +6-85,2-88 +13-14,14-96 +52-61,53-62 +38-42,34-43 +30-31,23-32 +7-95,6-94 +94-95,49-65 +18-97,17-96 +7-87,8-88 +33-33,34-54 +56-68,55-78 +11-46,10-46 +3-96,2-95 +69-69,63-70 +67-83,84-84 +45-74,37-75 +1-3,4-41 +7-98,8-99 +9-31,10-32 +64-65,65-79 +28-30,12-29 +2-70,69-71 +2-94,4-29 +84-89,16-83 +4-33,5-48 +52-91,52-95 +43-48,17-47 +56-58,57-60 +12-92,8-13 +68-97,39-69 +31-33,36-78 +1-95,96-96 +47-55,48-55 +98-98,2-99 +8-76,75-77 +9-43,5-25 +15-73,57-73 +28-42,28-40 +16-19,13-20 +15-28,29-29 +12-74,65-73 +55-93,3-93 +51-76,56-61 +37-77,61-76 +9-94,9-24 +24-49,49-76 +29-33,28-66 +43-53,33-54 +47-95,35-95 +60-73,61-74 +48-85,47-47 +48-68,18-48 +18-81,18-92 +4-97,3-5 +15-16,15-29 +5-9,8-91 +77-87,16-76 +23-99,22-98 +3-64,63-99 +5-86,91-93 +5-80,1-85 +6-54,6-46 +42-90,47-80 +43-45,44-79 +9-66,10-67 +88-89,6-89 +44-71,45-72 +21-86,85-86 +59-59,60-91 +17-95,18-99 +49-93,45-49 +36-86,37-81 +30-73,73-81 +42-46,38-56 +16-96,15-95 +3-30,4-35 +18-93,18-94 +14-23,13-45 +25-68,7-24 +36-55,28-90 +17-17,18-98 +3-91,3-91 +36-66,35-66 +1-77,2-77 +54-70,21-93 +26-73,26-64 +15-26,27-96 +31-48,48-82 +22-64,21-64 +74-99,54-73 +24-26,25-67 +24-24,25-88 +25-25,26-63 +24-81,80-87 +17-19,11-18 +19-88,87-88 +4-7,6-93 +54-71,72-72 +61-89,64-76 +96-98,36-97 +50-64,64-69 +66-93,97-99 +8-83,9-84 +5-96,6-96 +3-62,4-69 +74-94,52-95 +23-57,5-28 +9-93,10-93 +18-29,17-29 +67-85,16-31 +13-89,4-13 +36-75,15-36 +70-96,2-97 +20-29,28-93 +25-79,24-79 +25-92,17-93 +21-23,22-70 +33-74,34-75 +90-90,69-91 +39-95,38-95 +5-11,4-11 +35-36,36-94 +11-78,10-90 +56-85,57-86 +26-39,38-41 +2-99,3-99 +66-68,11-67 +39-85,81-81 +2-3,2-60 +20-32,20-31 +30-78,5-79 +14-74,7-82 +38-40,39-78 +53-55,54-67 +9-38,8-38 +3-99,2-99 +6-12,11-73 +96-96,91-95 +30-32,25-32 +80-81,4-81 +6-48,7-48 +11-54,2-12 +35-71,56-86 +41-65,40-66 +58-90,58-91 +53-87,25-87 +2-57,27-56 +5-65,4-66 +8-51,7-51 +84-98,18-28 +47-99,47-47 +64-71,70-78 +93-99,57-93 +70-72,1-71 +67-68,96-97 +31-61,51-52 +27-79,27-79 +50-77,51-78 +3-36,35-89 +90-91,18-91 +59-96,35-93 +14-58,13-13 +4-4,5-83 +10-33,10-21 +34-97,34-52 +13-99,98-99 +15-78,72-79 +7-51,4-35 +31-46,31-47 +41-59,41-60 +1-27,15-17 +50-83,63-97 +16-48,47-48 +8-70,69-99 +61-85,61-78 +3-87,2-3 +9-88,9-88 +19-21,8-29 +15-94,20-88 +1-83,1-84 +31-32,32-49 +2-5,4-27 +20-72,68-71 +63-64,50-63 +4-97,13-93 +3-68,88-96 +4-98,3-97 +20-20,21-34 +12-95,43-83 +32-33,33-71 +17-83,82-83 +31-36,25-32 +72-78,12-73 +70-81,69-69 +41-44,43-65 +82-82,18-81 +6-90,1-6 +6-11,6-11 +45-45,17-44 +10-87,9-9 +48-60,47-60 +28-73,28-73 +2-9,9-95 +41-98,97-99 +2-89,88-90 +1-93,2-93 +76-92,66-75 +1-70,26-70 +5-5,6-98 +24-82,49-61 +10-25,13-26 +13-22,17-21 +98-99,48-96 +1-83,3-99 +18-37,35-39 +4-99,15-99 +72-73,5-73 +7-99,8-99 +1-1,2-32 +39-89,39-88 +33-34,7-34 +76-79,74-79 +4-48,4-47 +6-96,16-93 +1-90,90-91 +2-99,54-86 +37-84,38-83 +5-5,6-99 +39-92,91-92 +71-73,19-72 +33-99,33-93 +10-16,15-88 +9-22,9-48 +11-38,18-37 +7-85,82-82 +7-33,6-33 +13-43,14-44 +16-43,15-15 +11-69,22-43 +10-94,10-93 +1-33,27-99 +25-44,32-42 +78-94,50-96 +23-85,27-87 +31-90,91-91 +50-52,51-52 +2-54,20-52 +64-82,65-82 +8-90,8-89 +34-88,35-89 +34-73,14-78 +22-25,26-76 +74-77,66-76 +85-89,25-85 +9-47,8-47 +29-93,28-92 +15-17,11-16 +82-85,2-81 +66-77,10-74 +3-46,6-25 +17-48,17-49 +93-98,94-99 +86-86,39-85 +15-97,33-98 +22-63,21-22 +36-81,37-82 +53-66,51-54 +87-94,10-88 +32-79,31-79 +15-67,66-67 +10-85,7-86 +25-37,25-93 +4-89,2-3 +35-76,35-86 +3-95,1-3 +6-99,5-57 +46-50,49-70 +19-56,19-89 +38-75,52-76 +13-48,12-47 +18-96,4-18 +2-95,1-96 +2-95,94-99 +32-41,31-42 +48-58,20-78 +57-86,16-70 +15-15,16-61 +98-99,6-97 +35-93,34-92 +57-57,58-87 +2-61,2-97 +7-96,59-96 +27-84,27-91 +30-98,29-97 +90-92,90-91 +3-70,3-71 +37-69,36-38 +35-51,45-52 +22-66,1-22 +4-90,2-3 +67-77,68-90 +11-70,7-11 +70-78,55-69 +96-97,4-97 +11-97,12-98 +48-55,47-54 +20-82,20-51 +44-45,45-57 +27-88,27-68 +98-99,13-99 +40-84,40-91 +3-69,1-73 +51-69,49-50 +4-53,2-2 +4-11,11-23 +2-99,4-97 +50-50,49-49 +64-94,53-95 +2-90,5-16 +14-96,53-97 +8-76,6-46 +35-84,12-36 +5-97,96-96 +58-65,3-89 +11-91,32-86 +27-89,26-26 +3-85,84-84 +37-52,51-91 +45-56,44-56 +21-22,22-84 +3-31,31-55 +52-89,88-90 +67-84,85-85 +31-75,76-76 +69-78,77-78 +22-84,71-95 +32-36,32-36 +4-92,91-93 +4-99,2-4 +87-88,59-88 +42-88,41-41 +43-54,20-54 +48-49,22-49 +30-63,29-44 +11-93,10-10 +61-87,14-61 +92-94,4-93 +94-98,32-94 +41-69,40-63 +77-78,32-78 +7-25,7-24 +94-95,2-93 +18-79,34-65 +47-88,89-94 +29-73,96-96 +22-58,58-98 +9-95,94-98 +43-66,66-89 +11-70,11-70 +9-79,10-80 +22-33,12-58 +42-73,42-74 +1-87,2-87 +2-20,3-75 +14-61,15-62 +17-18,9-18 +8-95,9-96 +94-95,7-95 +9-79,89-91 +2-98,48-55 +1-3,3-43 +25-73,25-90 +1-77,1-77 +13-97,12-96 +97-98,33-83 +55-80,24-80 +84-93,59-89 +8-56,7-55 +17-94,93-95 +54-90,54-89 +62-63,24-61 +66-67,66-67 +37-41,42-62 +13-94,12-94 +8-73,8-82 +14-53,39-53 +49-60,24-46 +24-91,13-23 +84-97,2-96 +19-85,20-86 +27-79,11-45 +17-48,18-49 +23-86,16-87 +61-61,40-60 +2-86,1-86 +24-73,38-72 +14-93,79-89 +81-99,62-82 +23-56,57-74 +42-89,54-90 +60-62,7-61 +4-80,8-79 +3-71,4-70 +3-3,4-72 +6-44,6-81 +26-97,97-98 +8-41,41-42 +1-99,1-98 +26-93,76-93 +90-91,16-90 +60-78,59-93 +57-59,87-97 +18-25,25-40 +19-97,21-82 +79-87,20-88 +41-89,40-89 +25-80,28-55 +4-81,3-92 +15-88,15-59 +46-79,51-83 +52-71,70-95 +6-97,6-98 +15-91,92-92 +22-96,96-97 +61-86,85-86 +75-94,74-97 +67-73,72-86 +5-88,6-89 +2-70,12-66 +13-15,14-30 +2-92,1-1 +75-97,75-97 +55-63,50-63 +39-81,76-78 +62-86,30-96 +44-99,61-86 +7-66,7-59 +31-47,13-30 +40-88,87-89 +6-95,96-96 +4-89,4-91 +8-99,7-99 +11-93,10-55 +56-58,57-73 +1-85,86-86 +52-60,52-87 +2-98,3-98 +1-92,3-26 +3-5,4-23 +1-99,2-99 +15-67,42-96 +65-65,62-67 +21-21,9-20 +54-64,28-53 +24-84,51-85 +32-95,3-96 +4-84,2-97 +1-87,1-87 +6-88,5-88 +48-79,47-62 +5-97,4-4 +22-46,21-23 +4-67,11-47 +28-29,29-68 +3-68,1-3 +6-94,4-4 +26-43,26-88 +3-46,4-53 +88-90,39-89 +77-96,50-78 +19-83,98-98 +4-26,1-82 +10-83,82-83 +1-2,3-82 +22-22,8-21 +35-51,34-85 +1-99,98-98 +20-45,14-21 +2-74,1-75 +1-5,5-21 +14-98,14-99 +7-91,9-92 +16-51,6-55 +27-63,13-63 +86-86,54-87 +31-96,16-96 +25-98,98-99 +4-92,4-93 +51-81,50-82 +18-86,40-85 +37-59,25-66 +80-97,59-81 +2-99,85-98 +54-86,55-85 +11-39,11-37 +11-13,12-62 +65-91,98-98 +22-38,37-45 +8-32,9-32 +61-84,83-85 +27-72,11-72 +90-94,12-90 +9-97,9-68 +3-95,4-95 +73-73,58-74 +13-16,12-14 +71-89,45-72 +44-72,44-73 +56-58,57-71 +47-53,43-52 +50-60,10-49 +6-19,20-67 +49-88,69-87 +48-60,21-70 +98-98,85-97 +18-18,19-30 +50-82,81-82 +7-63,8-63 +79-96,78-95 +4-96,1-1 +79-80,1-80 +20-78,19-81 +26-85,26-27 +15-24,15-24 +2-80,3-81 +5-74,4-4 +2-2,3-92 +1-87,7-84 +84-85,34-85 +18-96,18-19 +50-52,51-89 +82-82,48-82 +17-54,18-58 +82-96,3-97 +20-66,67-94 +7-83,8-83 +2-2,3-67 +2-97,96-99 +57-69,70-71 +70-83,69-83 +37-96,39-42 +51-99,50-99 +18-90,19-90 +76-99,75-88 +15-52,6-14 +3-94,62-95 +60-81,59-59 +11-26,11-51 +8-92,7-92 +31-80,79-81 +92-93,3-93 +14-35,2-13 +31-85,84-85 +32-91,32-90 +31-61,30-61 +18-20,19-48 +19-60,20-20 +73-97,26-85 +31-84,85-85 +13-80,12-80 +2-83,83-98 +13-58,14-57 +53-86,22-86 +8-76,7-9 +28-61,29-62 +5-99,4-5 +96-98,2-97 +4-95,94-94 +1-58,6-93 +33-62,4-63 +18-48,8-14 +11-85,86-99 +36-58,36-59 +48-75,49-96 +11-92,91-93 +67-77,66-67 +13-83,73-82 +43-61,60-77 +68-90,67-68 +89-90,90-90 +27-95,26-26 +31-31,11-36 +9-97,11-95 +75-86,76-86 +19-19,20-64 +99-99,7-97 +69-69,69-70 +9-99,8-99 +83-91,10-92 +22-22,21-21 +41-67,40-42 +2-8,7-61 +47-63,46-68 diff --git a/Advent-of-Code-2022/aoc-4/main.c b/Advent-of-Code-2022/aoc-4/main.c new file mode 100644 index 0000000..56dfcfd --- /dev/null +++ b/Advent-of-Code-2022/aoc-4/main.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +#if 0 + #define PART part1 +#else + #define PART part2 +#endif + +#if 0 + #define FILENAME "sample.txt" +#else + #define FILENAME "input.txt" +#endif + +int res = 0; + +void part1(int *longer, int *shorter) +{ + if(longer[0] <= shorter[0] && + longer[1] >= shorter[1]) + res++; +} + +void part2(int *longer, int *shorter) +{ + if((shorter[0] >= longer[0] && shorter[0] <= longer[1]) || + (shorter[1] >= longer[0] && shorter[1] <= longer[1])) + res++; +} + +void parse() +{ + FILE *fp = fopen(FILENAME, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file: %s\n", FILENAME); + exit(1); + } + + char line[256]; + while(fgets(line, sizeof(line), fp)) + { + int range1[2]; + int range2[2]; + + char *r1 = strtok(line, ","); + char *r2 = strtok(NULL, ","); + assert(strtok(NULL, ",") == NULL); + + range1[0] = atoi(strtok(r1, "-")); + range1[1] = atoi(strtok(NULL, "-")); + assert(strtok(NULL, "-") == NULL); + + range2[0] = atoi(strtok(r2, "-")); + range2[1] = atoi(strtok(NULL, "-")); + assert(strtok(NULL, "-") == NULL); + + int len1 = range1[1] - range1[0] + 1; + int len2 = range2[1] - range2[0] + 1; + int *longer = (len1 > len2) ? range1 : range2; + int *shorter = (len1 > len2) ? range2 : range1; + + PART(longer, shorter); + } + + fclose(fp); +} + +int main(void) +{ + parse(); + printf("%d\n", res); + return 0; +} diff --git a/Advent-of-Code-2022/aoc-4/sample.txt b/Advent-of-Code-2022/aoc-4/sample.txt new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/Advent-of-Code-2022/aoc-4/sample.txt @@ -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 -- cgit v1.2.3