aboutsummaryrefslogtreecommitdiff
path: root/day04
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2022-12-04 12:41:13 +0000
committerNat Lasseter <user@4574.co.uk>2022-12-04 12:41:13 +0000
commit408c7a8b7dce5246a595b7737de6a1b7825a53b8 (patch)
tree49976281d51f0ac58d6c3aed3817bf302ca333ab /day04
parentc62e6e28ad065948557aea88958631462a42b1ec (diff)
Day 04
Diffstat (limited to 'day04')
-rw-r--r--day04/input1000
-rw-r--r--day04/part1.rb9
-rw-r--r--day04/part2.rb15
-rw-r--r--day04/test6
4 files changed, 1030 insertions, 0 deletions
diff --git a/day04/input b/day04/input
new file mode 100644
index 0000000..44529e5
--- /dev/null
+++ b/day04/input
@@ -0,0 +1,1000 @@
+14-38,14-14
+2-10,3-55
+36-90,36-46
+9-97,8-87
+75-92,51-92
+6-82,1-83
+21-79,29-80
+26-66,27-27
+11-32,11-32
+6-90,91-91
+36-78,21-65
+66-66,23-66
+22-23,22-95
+3-82,3-35
+1-92,93-93
+1-96,1-1
+12-54,9-53
+80-98,4-80
+7-63,3-63
+2-2,2-21
+33-95,85-94
+60-60,60-80
+76-97,96-98
+1-98,2-2
+69-96,68-98
+63-84,63-63
+24-31,23-28
+16-71,40-70
+30-63,64-64
+20-61,64-77
+57-90,17-58
+57-58,12-58
+10-74,10-74
+14-65,64-72
+95-99,8-90
+26-46,45-75
+18-66,17-19
+21-56,21-21
+42-75,70-74
+5-46,45-47
+20-79,20-79
+1-99,2-99
+16-31,17-30
+10-30,8-9
+1-99,1-99
+51-91,50-97
+18-39,18-39
+9-97,4-9
+5-76,6-6
+88-92,88-89
+11-91,19-92
+70-74,2-42
+65-93,94-94
+10-96,9-95
+8-40,6-35
+3-11,12-12
+17-88,17-89
+8-41,7-9
+9-60,60-66
+56-86,86-87
+58-67,58-86
+14-90,7-90
+3-82,2-81
+54-56,20-55
+2-88,4-87
+5-79,6-6
+95-95,19-95
+37-94,38-94
+2-12,2-36
+9-46,46-47
+58-80,66-81
+96-98,1-97
+72-85,84-85
+52-55,52-61
+74-76,6-75
+1-65,2-88
+22-58,22-58
+29-97,30-96
+3-5,5-62
+2-89,2-72
+20-62,69-76
+63-66,62-65
+18-20,19-35
+17-88,17-87
+14-99,13-98
+46-84,46-81
+4-98,3-5
+3-76,75-75
+84-92,91-95
+38-83,4-83
+4-53,5-77
+58-86,58-74
+21-97,96-97
+7-7,7-34
+9-38,9-36
+29-43,43-78
+56-97,55-56
+89-90,9-89
+4-47,48-88
+23-58,58-76
+5-55,32-55
+34-48,41-45
+98-98,44-99
+14-92,48-92
+22-96,23-98
+25-43,73-95
+71-79,72-77
+74-94,93-95
+14-90,89-89
+5-32,4-99
+4-58,4-59
+4-96,4-4
+62-83,54-84
+66-67,67-68
+25-42,25-42
+13-79,12-78
+4-65,2-92
+4-65,3-4
+6-83,7-82
+74-76,41-75
+3-62,61-62
+10-39,11-30
+19-93,3-42
+25-25,11-26
+37-52,53-77
+3-97,97-98
+22-67,23-77
+47-96,35-35
+25-84,23-25
+6-86,86-86
+62-62,48-62
+41-95,42-95
+12-75,13-76
+7-69,6-70
+78-91,35-78
+17-80,79-81
+49-77,50-78
+96-99,20-97
+7-9,8-78
+85-86,58-87
+8-8,8-80
+17-66,43-67
+48-60,22-65
+9-67,67-67
+9-45,10-62
+43-73,44-83
+80-96,80-93
+72-87,85-88
+16-61,13-16
+92-92,2-91
+22-43,42-43
+31-83,30-79
+38-95,38-97
+63-85,71-84
+11-11,11-19
+13-14,13-56
+2-5,4-81
+59-64,62-65
+71-89,8-59
+93-99,87-94
+25-25,26-72
+56-98,57-97
+33-36,37-94
+38-85,84-86
+1-79,78-94
+77-98,76-99
+14-72,13-71
+17-92,18-86
+18-99,57-98
+2-87,3-87
+78-95,86-94
+43-44,32-46
+59-62,60-62
+12-24,24-25
+41-66,21-66
+13-82,13-83
+53-87,11-87
+7-96,7-96
+24-26,25-32
+13-70,8-13
+12-93,12-17
+4-39,5-38
+95-97,73-96
+73-81,74-83
+57-62,63-63
+58-59,56-59
+38-98,38-97
+20-75,19-74
+8-62,74-99
+2-96,3-91
+7-97,6-8
+1-99,1-99
+41-81,42-80
+91-91,43-92
+4-73,4-4
+40-43,42-54
+37-66,47-56
+88-89,20-73
+10-98,10-98
+51-81,51-51
+36-81,5-36
+16-64,61-64
+22-98,21-99
+29-76,75-77
+2-95,1-96
+58-58,2-58
+10-62,11-42
+8-8,35-90
+53-78,53-94
+9-74,10-73
+41-86,40-86
+2-40,3-80
+26-26,25-62
+38-99,37-97
+24-91,25-98
+26-93,25-94
+31-53,1-54
+16-47,24-47
+25-91,39-92
+22-91,40-92
+8-23,8-8
+83-88,83-90
+62-85,63-86
+27-48,27-27
+50-58,37-59
+5-74,5-64
+29-77,29-77
+19-24,19-19
+12-12,11-87
+37-87,38-71
+99-99,12-95
+77-77,24-78
+72-85,71-99
+7-7,7-87
+3-97,58-96
+14-16,15-99
+47-94,93-94
+36-82,14-82
+2-22,9-21
+2-74,73-75
+88-88,46-88
+1-93,93-93
+48-67,48-67
+78-78,12-77
+52-99,34-52
+66-66,65-71
+64-92,65-91
+18-44,19-58
+38-44,27-38
+44-99,44-85
+69-84,31-81
+44-86,44-86
+76-77,2-76
+71-72,24-72
+23-72,24-72
+8-23,9-22
+76-96,92-94
+7-77,76-76
+14-15,17-79
+13-99,14-96
+34-90,33-43
+6-81,6-81
+17-73,3-11
+2-22,3-23
+88-99,87-98
+6-52,52-53
+8-93,76-94
+88-95,84-96
+64-94,64-67
+12-29,11-30
+50-58,32-59
+70-90,71-90
+50-57,58-59
+2-65,1-64
+9-45,8-44
+57-90,56-88
+7-84,7-7
+46-84,45-45
+17-59,16-58
+3-11,11-15
+64-93,20-70
+54-93,54-92
+23-24,23-92
+17-82,17-26
+21-79,78-94
+18-94,93-94
+25-40,26-84
+20-83,19-83
+20-20,20-90
+1-96,88-96
+12-57,13-13
+26-99,26-98
+69-70,39-69
+14-83,82-82
+24-99,24-98
+2-10,10-82
+16-62,41-82
+1-71,1-72
+26-30,25-29
+5-96,5-99
+8-8,7-61
+26-99,27-27
+26-90,8-19
+22-89,22-90
+7-68,69-69
+57-59,3-58
+92-93,86-92
+51-83,50-77
+87-87,11-86
+2-51,3-81
+63-65,25-64
+34-81,33-83
+5-37,5-91
+13-55,1-24
+15-15,15-83
+18-22,18-88
+11-41,11-41
+93-95,6-94
+65-68,65-70
+31-87,32-81
+11-84,3-85
+96-97,32-97
+27-67,66-68
+87-89,22-88
+31-75,24-76
+18-96,17-97
+3-95,4-36
+66-99,67-97
+21-71,22-72
+56-77,78-85
+2-96,3-95
+20-93,92-92
+35-97,96-98
+32-37,17-36
+8-95,7-94
+21-81,7-81
+68-69,68-89
+22-47,23-48
+23-78,23-24
+50-52,12-51
+14-96,14-98
+18-46,34-45
+2-88,1-2
+11-60,10-12
+97-97,60-97
+18-70,19-71
+5-94,93-95
+68-95,67-87
+12-87,93-95
+58-68,57-60
+92-93,5-92
+21-21,20-71
+48-82,81-99
+9-59,10-84
+29-50,29-94
+14-15,14-15
+65-90,65-80
+10-36,10-35
+24-81,80-82
+9-10,10-51
+48-54,54-54
+49-50,50-56
+58-92,57-70
+16-27,4-17
+1-98,23-99
+31-94,93-93
+39-41,8-40
+87-95,95-95
+58-90,59-89
+9-97,30-97
+10-79,10-78
+3-41,3-41
+3-63,62-63
+65-97,66-66
+83-83,65-84
+16-60,17-59
+61-83,63-84
+66-68,66-67
+78-78,18-79
+13-83,12-82
+20-69,21-69
+25-95,60-96
+22-22,22-97
+28-85,2-84
+65-84,84-85
+43-87,88-88
+4-4,3-99
+4-84,2-4
+53-55,45-54
+16-17,11-70
+44-98,44-97
+43-64,43-58
+28-37,19-27
+23-77,76-78
+1-92,6-92
+52-86,52-86
+59-86,58-59
+8-94,7-95
+48-98,98-98
+46-49,47-48
+31-82,32-85
+58-87,57-87
+45-47,46-86
+61-86,61-76
+38-84,37-85
+92-92,53-93
+21-68,22-68
+69-98,70-98
+17-91,92-92
+35-35,35-35
+17-53,17-53
+26-40,37-37
+22-88,22-88
+10-30,10-30
+97-99,27-98
+17-37,17-37
+19-31,19-28
+4-86,3-85
+11-32,12-31
+67-77,67-98
+12-40,9-9
+36-83,83-84
+10-71,70-70
+57-92,15-84
+1-4,3-91
+3-11,7-12
+31-90,90-91
+5-22,2-5
+6-91,5-91
+92-92,40-72
+4-8,12-97
+5-76,52-75
+5-91,91-91
+2-99,1-96
+19-43,19-43
+48-98,47-97
+25-96,19-97
+3-91,3-99
+11-13,12-38
+67-71,17-71
+11-11,10-99
+1-6,5-97
+57-57,35-57
+87-89,24-88
+92-92,29-93
+31-35,28-36
+20-80,19-19
+82-82,5-82
+10-31,32-55
+18-82,28-81
+29-73,29-88
+10-93,10-10
+40-42,40-42
+22-32,22-26
+71-72,58-71
+36-97,36-41
+5-94,5-98
+96-99,87-97
+12-95,13-95
+97-99,20-98
+24-84,24-84
+76-92,75-97
+14-54,14-53
+37-51,37-52
+69-71,35-70
+41-41,35-40
+35-92,92-92
+58-68,57-67
+57-75,27-76
+21-85,22-84
+42-59,41-41
+96-96,1-96
+27-29,28-98
+14-81,15-15
+42-94,42-93
+22-59,15-60
+3-98,3-69
+15-15,3-15
+67-82,36-47
+27-54,10-55
+44-57,43-56
+56-68,56-56
+90-92,33-91
+92-94,82-95
+8-69,69-69
+37-76,36-75
+21-96,1-21
+15-15,10-18
+83-83,9-83
+11-11,11-64
+34-94,25-93
+54-77,77-77
+34-70,35-70
+20-96,20-77
+59-64,32-63
+28-75,27-97
+3-85,2-86
+52-89,52-91
+43-54,45-53
+20-27,20-28
+45-91,68-89
+7-61,12-84
+7-94,6-95
+32-33,32-79
+2-5,5-99
+7-63,6-53
+16-78,17-78
+19-54,54-54
+66-74,66-75
+20-93,21-93
+42-98,1-99
+5-24,4-5
+10-95,94-95
+1-99,1-99
+81-81,81-96
+39-39,23-38
+3-41,3-4
+35-71,36-36
+11-39,38-88
+39-56,40-57
+1-6,6-82
+11-34,1-34
+7-7,7-94
+3-97,2-98
+47-99,47-99
+66-91,96-97
+5-89,97-99
+62-62,36-61
+7-17,6-16
+96-96,57-78
+83-95,13-94
+98-99,1-99
+2-93,92-93
+93-93,51-92
+23-23,23-84
+45-82,44-82
+7-32,7-33
+9-97,10-75
+23-77,25-69
+9-91,8-9
+4-95,47-93
+64-67,2-96
+48-72,72-73
+46-92,45-93
+2-95,94-95
+68-76,69-69
+2-51,8-51
+57-81,82-94
+7-60,13-60
+24-71,23-35
+24-97,24-97
+24-94,32-95
+21-35,21-22
+22-51,23-76
+32-94,32-91
+9-94,9-90
+87-88,9-87
+5-12,7-13
+35-73,74-74
+61-64,48-65
+17-94,71-94
+54-54,29-57
+75-77,19-76
+14-14,15-72
+14-14,14-43
+29-33,29-95
+1-1,1-81
+46-81,80-80
+39-66,10-66
+55-88,55-71
+91-94,34-96
+28-93,27-89
+56-97,55-71
+17-94,93-95
+27-67,26-66
+90-99,83-98
+24-25,24-70
+42-98,79-99
+94-94,46-88
+7-71,70-81
+29-95,28-83
+85-85,3-84
+12-89,63-88
+8-31,9-9
+3-93,70-95
+19-19,19-94
+16-40,1-41
+54-88,88-88
+39-39,29-39
+39-59,59-59
+20-80,19-79
+2-7,2-53
+20-97,19-58
+4-70,4-70
+56-89,55-90
+86-95,95-95
+66-93,65-73
+4-84,5-85
+34-88,33-41
+26-61,26-78
+48-79,49-79
+66-99,52-99
+77-77,43-78
+49-90,50-80
+17-71,16-37
+45-91,45-90
+71-71,27-70
+96-96,3-96
+15-89,14-90
+17-96,7-96
+95-95,2-94
+12-85,11-54
+58-67,34-73
+28-54,29-90
+6-84,5-83
+11-49,48-48
+71-71,11-72
+29-99,99-99
+18-92,19-93
+85-86,35-85
+51-73,51-89
+1-99,57-99
+29-53,28-81
+6-62,7-63
+78-78,77-79
+18-43,18-71
+31-32,32-50
+14-39,40-40
+41-62,42-61
+3-69,5-68
+51-57,48-58
+40-40,41-98
+11-12,11-47
+8-81,8-84
+24-54,10-55
+4-48,5-97
+11-90,11-56
+78-92,78-78
+10-66,67-76
+92-92,13-93
+75-98,67-68
+4-95,2-96
+15-70,16-23
+21-67,20-21
+38-48,38-47
+77-81,80-82
+25-74,30-73
+90-90,91-91
+28-70,20-71
+16-89,37-93
+55-68,34-69
+7-97,50-97
+16-38,17-37
+81-81,34-81
+28-81,27-29
+20-73,19-29
+51-83,52-82
+57-57,56-56
+63-76,20-62
+47-56,46-48
+14-63,62-62
+16-64,63-65
+86-97,87-96
+3-3,3-57
+26-27,20-27
+2-99,3-3
+1-2,1-49
+16-58,31-59
+2-14,2-46
+6-31,5-50
+19-65,19-65
+34-38,27-37
+2-91,3-90
+5-78,5-78
+7-20,6-19
+44-60,44-59
+61-83,61-61
+35-38,36-57
+4-98,5-99
+5-5,4-86
+4-64,21-88
+34-73,34-76
+52-78,51-79
+95-97,7-96
+50-56,51-57
+4-97,5-97
+2-80,11-79
+15-33,4-15
+1-19,19-85
+2-98,17-97
+40-49,39-84
+17-19,18-75
+49-49,48-74
+72-72,12-72
+15-77,14-98
+2-85,6-58
+45-74,32-44
+10-95,9-9
+83-83,16-83
+62-80,63-90
+25-49,26-52
+67-75,25-59
+25-83,26-73
+52-91,52-52
+69-88,68-89
+56-85,55-95
+9-97,97-97
+36-92,6-36
+45-46,44-46
+28-41,28-41
+18-82,28-87
+30-31,31-96
+5-81,6-6
+14-89,34-88
+27-91,27-27
+96-96,31-96
+16-18,17-30
+17-17,16-84
+3-43,31-45
+31-62,30-61
+48-95,47-60
+16-78,15-78
+48-48,34-48
+3-94,2-95
+1-1,2-2
+86-87,84-89
+31-49,31-66
+13-13,13-46
+4-95,79-95
+3-33,1-34
+4-69,10-69
+29-89,83-90
+25-70,23-71
+59-96,60-83
+78-90,15-83
+15-96,15-76
+80-98,12-79
+41-46,42-47
+1-98,2-97
+25-70,26-71
+4-30,83-93
+43-59,42-59
+25-47,24-48
+2-99,3-99
+1-79,80-80
+2-93,1-92
+7-10,7-10
+55-66,54-65
+9-73,9-73
+23-56,22-56
+22-44,21-45
+11-78,12-79
+7-92,8-87
+58-93,16-94
+24-69,24-94
+94-94,39-94
+34-58,33-58
+49-78,77-77
+7-18,6-19
+74-74,73-93
+44-81,48-81
+11-85,84-84
+29-91,30-92
+17-93,16-17
+1-48,2-78
+11-93,94-94
+12-97,96-96
+6-94,6-6
+19-92,56-67
+10-53,2-10
+14-81,13-90
+23-92,23-93
+38-70,70-71
+42-98,42-66
+37-86,38-99
+11-97,1-97
+48-81,49-49
+11-81,9-20
+44-92,15-44
+68-95,67-97
+57-74,57-74
+34-39,16-38
+27-79,28-80
+50-59,10-60
+13-41,13-30
+77-79,45-78
+24-72,24-80
+12-12,12-66
+10-81,81-82
+4-60,3-61
+31-85,30-31
+23-56,23-69
+21-84,83-84
+8-92,91-91
+27-86,85-91
+64-96,63-99
+2-50,3-50
+70-88,2-71
+11-27,12-27
+31-32,31-55
+2-73,73-85
+27-28,27-27
+68-94,68-79
+4-95,67-96
+22-79,8-22
+3-71,2-70
+6-92,1-92
+74-97,73-93
+2-73,1-66
+10-11,10-96
+29-34,30-34
+43-93,23-42
+25-28,27-28
+52-93,53-94
+62-81,46-63
+8-22,8-8
+10-93,92-94
+10-96,98-99
+2-83,1-1
+14-23,13-17
+27-97,71-96
+2-3,1-8
+4-79,4-58
+52-96,53-89
+19-97,11-19
+18-84,17-85
+39-99,39-88
+25-34,26-31
+41-66,41-65
+2-82,1-83
+8-39,40-40
+35-58,26-58
+5-52,4-51
+4-97,34-96
+53-84,3-74
+3-9,3-97
+2-42,8-96
+4-6,5-95
+53-77,22-53
+16-83,15-82
+41-50,41-74
+11-12,11-78
+39-81,38-82
+7-36,8-37
+3-99,3-97
+50-53,52-54
+7-98,98-98
+30-73,31-31
+90-90,73-90
+74-83,74-83
+45-66,7-65
+15-95,15-16
+53-86,54-87
+1-7,7-86
+64-64,29-63
+17-31,17-75
+26-40,48-98
+18-34,17-33
+45-45,5-45
+24-42,23-42
+66-90,65-91
+15-76,8-27
+4-56,4-56
+59-59,59-66
+20-52,29-63
+56-57,54-57
+90-99,46-73
+6-98,6-98
+7-75,7-75
+28-96,13-96
+39-49,33-50
+45-60,61-79
+8-81,8-90
+6-7,7-73
+43-88,1-99
+87-89,53-88
+79-80,32-80
+7-15,7-15
+40-41,8-40
+28-99,29-56
+47-89,90-90
+66-66,46-66
+6-99,7-98
+13-97,96-97
+67-67,22-68
+61-88,27-89
+12-33,13-13
+3-19,3-40
+10-61,10-99
+13-29,29-97
+50-83,9-49
+1-21,1-91
+48-48,10-48
+51-81,51-51
+39-41,40-98
+61-84,62-83
+4-94,4-93
+3-3,2-29
+87-89,82-88
+3-16,3-40
+36-48,48-48
+27-54,26-53
+50-91,49-91
+1-99,1-1
+16-18,17-41
+74-75,17-75
+25-61,7-25
+40-40,39-83
+41-61,55-61
+58-89,23-89
+10-78,77-79
+9-68,1-9
+9-49,10-94
+64-88,88-88
+43-88,42-89
+55-94,4-94
+23-60,46-59
+14-80,79-81
+39-46,38-45
+35-69,58-68
+38-97,97-97
+7-39,7-87
+33-96,33-71
+3-43,26-42
+1-32,2-96
+55-99,54-56
+50-56,48-55
+44-92,93-93
+10-67,9-9
+31-73,3-31
+8-91,9-9
+19-19,19-61
+63-94,63-94
+7-29,94-99
+11-87,10-92
+10-70,69-71
+15-85,14-85
+11-29,10-13
+61-96,56-95
+6-58,7-7
+79-79,64-78
+70-89,11-90
+7-73,7-73
+62-94,14-62
+15-99,15-25
+8-30,7-71
+20-49,19-21
+20-36,10-36
+9-80,7-9
+42-87,30-88
+9-95,10-96
+10-63,50-90
+13-16,7-15
+25-87,88-88
+5-62,3-62
+9-13,11-99
+5-72,18-73
+75-75,8-75
+1-95,3-95
+18-91,91-91
+12-96,12-13
+32-78,33-78
+2-83,83-95
+33-65,33-33
+66-82,1-67
+65-93,64-93
+35-47,19-34
+22-47,21-42
+4-54,3-55
+44-98,44-45
+99-99,7-97
+95-95,7-94
+43-84,42-83
+28-48,29-67
+2-98,2-3
+2-97,3-95
+68-68,1-67
+20-29,4-30
+16-35,5-47
+22-76,99-99
+6-29,6-29
+24-58,47-57
+2-7,7-68
+56-58,46-57
+36-45,35-71
+13-18,18-18
+13-42,14-43
+72-92,91-93
+82-87,76-84
+79-81,14-80
+38-65,38-38
+42-42,1-41
+2-42,20-67
+20-70,20-70
+28-88,89-94
+6-54,7-55
+77-92,77-94
+37-99,67-90
+9-11,56-71
+43-43,34-43
diff --git a/day04/part1.rb b/day04/part1.rb
new file mode 100644
index 0000000..529572c
--- /dev/null
+++ b/day04/part1.rb
@@ -0,0 +1,9 @@
+pairs = $stdin.readlines.map { |line|
+ line.strip.split(?,).map { |range|
+ Range.new(*range.split(?-).map(&:to_i))
+ }
+}
+
+puts pairs.select { |a, b|
+ a.cover?(b) || b.cover?(a)
+}.count
diff --git a/day04/part2.rb b/day04/part2.rb
new file mode 100644
index 0000000..d02c1e2
--- /dev/null
+++ b/day04/part2.rb
@@ -0,0 +1,15 @@
+class Range
+ def overlap?(other)
+ cover?(other.first) || other.cover?(first)
+ end
+end
+
+pairs = $stdin.readlines.map { |line|
+ line.strip.split(?,).map { |range|
+ Range.new(*range.split(?-).map(&:to_i))
+ }
+}
+
+puts pairs.select { |a, b|
+ a.overlap?(b)
+}.count
diff --git a/day04/test b/day04/test
new file mode 100644
index 0000000..9f9e9cf
--- /dev/null
+++ b/day04/test
@@ -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