aboutsummaryrefslogtreecommitdiffstats
path: root/day4
diff options
context:
space:
mode:
authorOrfeas <38209077+0xfea5@users.noreply.github.com>2024-06-08 13:50:47 +0300
committerOrfeas <38209077+0xfea5@users.noreply.github.com>2024-06-08 13:50:47 +0300
commit7be570c4a6e86fb7060f0bc06910ca57003dfe90 (patch)
treea998f976596cb902cd8988d74f756b72660bc29c /day4
parentDay 21 (part1) (diff)
downloadaoc22-main.tar.gz
aoc22-main.zip
Update file names and init.shHEADmain
Diffstat (limited to 'day4')
-rw-r--r--day4/example.txt6
-rw-r--r--day4/input.txt1000
-rw-r--r--day4/solution.nim42
3 files changed, 0 insertions, 1048 deletions
diff --git a/day4/example.txt b/day4/example.txt
deleted file mode 100644
index 9f9e9cf..0000000
--- a/day4/example.txt
+++ /dev/null
@@ -1,6 +0,0 @@
12-4,6-8
22-3,4-5
35-7,7-9
42-8,3-7
56-6,4-6
62-6,4-8
diff --git a/day4/input.txt b/day4/input.txt
deleted file mode 100644
index 5304059..0000000
--- a/day4/input.txt
+++ /dev/null
@@ -1,1000 +0,0 @@
136-92,35-78
226-31,25-27
317-72,16-71
43-77,76-90
520-22,21-87
65-75,6-75
742-44,43-95
851-73,50-52
981-89,80-81
107-58,47-58
1172-91,20-92
1227-64,51-64
135-94,94-95
1488-93,88-89
157-45,46-91
1630-40,29-29
1781-90,80-90
184-71,4-71
1968-83,65-84
201-4,3-79
2194-95,35-82
2230-84,31-97
236-82,81-86
2488-88,4-89
2541-97,40-89
2695-99,34-94
2718-56,18-56
2853-64,22-53
295-9,9-71
3018-41,40-66
3138-39,38-78
3223-99,22-94
3334-54,34-53
3433-76,85-94
3572-91,63-79
3633-94,93-94
3756-82,20-56
3860-85,60-86
3931-76,31-33
4029-79,78-80
419-9,66-69
426-97,6-75
4340-78,39-77
4414-30,14-15
4591-94,88-98
461-23,10-23
479-84,7-9
4875-76,75-98
4945-87,45-46
5011-11,11-11
5116-64,64-65
5260-60,20-61
5348-81,93-94
545-48,32-47
5537-75,74-75
5613-76,13-13
5715-93,92-96
5841-86,86-96
5948-92,64-91
601-9,2-97
6143-56,55-55
627-99,98-99
6398-99,1-99
6415-97,7-99
6576-76,32-77
6671-76,76-77
6713-28,13-29
6838-69,42-50
6949-49,50-77
7068-84,71-83
7126-51,32-51
7212-40,39-63
7321-92,9-88
747-65,65-69
7556-76,56-77
7640-62,62-62
7735-96,92-95
7837-99,12-86
7994-98,4-81
8032-38,34-39
8111-94,24-93
821-97,1-60
837-77,7-59
8462-81,80-96
8538-83,82-82
8644-44,43-98
8722-23,22-62
8828-97,16-97
8953-88,67-88
902-2,56-97
9141-72,71-72
9278-80,47-79
931-1,2-41
9423-99,33-98
9533-98,61-97
9680-95,80-80
978-90,8-91
984-90,50-89
9994-94,3-95
1003-83,2-99
10145-52,12-44
10222-65,66-71
1039-72,72-73
1042-62,2-82
10540-61,30-60
10657-87,25-56
10776-78,77-77
10816-88,87-88
10914-77,73-77
11037-90,36-38
11110-75,11-11
11237-99,3-97
11347-48,45-47
1146-92,7-91
11560-74,60-61
11620-29,8-21
11795-96,47-95
11863-70,31-63
1196-97,6-76
12019-91,19-92
12150-92,49-50
12217-96,18-97
1233-4,3-93
12413-51,1-13
12534-87,23-33
1262-99,98-98
1274-6,7-76
12846-60,36-45
12950-80,25-51
13060-61,24-61
13197-98,3-98
13233-34,83-99
13330-76,22-77
13427-72,72-94
13547-96,31-47
13626-90,11-27
13747-87,3-72
13886-91,9-87
13932-79,78-79
14072-95,94-94
14188-96,8-89
14211-84,12-98
1435-8,8-29
1446-38,86-86
14514-33,5-33
14620-95,39-94
1476-99,12-93
14852-91,52-90
1493-99,2-72
15072-96,56-90
1517-84,7-8
15220-37,14-37
15326-74,74-75
15440-54,4-71
15542-42,93-94
15653-69,23-52
15720-96,95-96
1581-18,18-83
1592-3,2-69
16036-87,87-87
1618-94,8-94
16259-99,59-60
16315-35,11-35
1646-26,5-26
1657-12,11-80
16679-79,79-79
1672-47,46-47
16876-96,96-97
16912-79,11-77
17045-71,46-94
17162-63,62-94
17230-84,84-85
1739-35,9-13
17418-60,18-61
17513-90,13-85
1762-38,1-2
17776-81,24-54
17848-49,48-95
17959-92,58-69
18072-72,15-73
18115-16,15-99
18279-85,60-86
18358-58,46-59
18455-60,3-54
18522-26,26-58
1866-86,7-85
18766-76,47-66
18852-73,52-53
18921-76,20-77
19044-73,16-77
19129-80,30-30
19215-47,14-16
1933-75,1-3
19455-61,9-56
19537-55,36-82
19664-83,83-84
1979-91,41-89
19822-86,33-85
1996-19,5-34
20080-92,93-93
20199-99,85-98
20296-99,14-97
2032-72,5-59
20493-94,56-94
20534-83,34-86
20633-34,34-73
20717-84,18-44
20882-83,26-83
2093-85,18-84
21088-88,9-88
21193-93,27-94
21212-13,12-14
2138-90,8-42
21478-86,41-77
21563-79,80-81
21615-66,14-16
21777-77,28-76
2189-96,8-10
21919-78,77-79
22013-95,72-93
22113-49,14-14
22284-85,84-95
22325-37,25-37
22449-93,49-91
22524-78,5-38
2262-92,2-92
22717-90,16-90
2288-50,8-50
22976-99,76-98
23071-86,77-86
23170-71,54-70
2328-84,39-84
23340-58,55-58
2348-87,1-9
2355-7,6-85
23625-97,24-25
2379-97,14-96
23817-48,10-47
23981-87,30-80
2403-83,83-84
2412-7,6-42
24220-70,70-93
24367-85,17-61
2447-18,6-20
24521-73,20-22
24680-81,18-79
24743-95,44-96
24838-45,44-44
24915-91,90-91
25032-44,34-43
25124-93,24-25
25210-16,11-12
25322-92,61-92
2543-7,6-73
25572-79,71-74
25634-47,34-46
25756-96,75-82
25831-48,48-81
25954-81,53-82
2602-91,93-97
26141-74,10-40
26251-63,52-86
26380-90,75-90
26486-87,10-87
26580-94,84-94
26646-47,9-47
26720-77,78-92
26838-38,17-37
26930-76,5-30
2706-58,58-77
27110-73,74-85
2721-96,2-31
27364-73,4-74
27460-79,59-77
2754-98,8-89
2767-9,8-78
2774-6,5-95
27829-93,53-90
27932-94,20-33
28078-91,38-79
28110-95,96-99
2825-97,86-96
2836-65,5-64
28428-71,7-72
28515-54,45-53
2863-87,46-99
2871-90,40-90
28844-86,19-86
2893-94,93-94
29092-93,1-93
29193-93,42-94
29290-97,21-91
29316-94,16-62
29420-27,79-86
29528-28,29-39
29630-94,29-30
29728-68,76-79
29854-73,54-55
29935-36,35-87
3005-42,43-47
30110-90,8-91
30215-74,23-49
30316-97,1-98
3042-82,82-89
3051-3,2-86
30616-87,15-86
3079-10,9-60
30814-90,10-14
30936-85,5-85
31036-41,37-89
31150-50,15-50
31282-86,85-86
31328-66,28-32
31415-84,14-14
31532-69,31-33
31631-95,30-96
31760-85,61-92
31810-87,86-87
31996-99,5-97
32097-97,39-96
32134-35,3-35
32251-88,33-88
32314-49,48-90
3244-51,52-56
3257-76,31-75
3263-99,3-87
32729-86,29-75
32861-64,61-65
32985-97,13-86
33059-67,6-58
33151-97,44-50
33221-64,64-93
3339-56,10-81
33420-51,50-51
33533-87,32-87
33618-79,5-90
33751-51,22-52
33824-83,21-25
33979-93,24-94
34014-14,13-83
34143-49,44-50
34272-72,10-73
34314-57,35-57
3444-63,3-4
3454-93,26-91
34626-93,25-26
34733-35,33-43
34836-87,87-92
34927-69,6-70
35038-60,30-39
35196-96,1-95
3522-96,99-99
35316-87,88-88
35441-52,41-51
35561-77,76-82
3569-77,3-10
35739-50,38-51
35812-63,12-62
35917-30,18-76
36022-86,22-23
3613-43,2-44
36221-66,66-66
3633-64,2-2
36460-65,60-65
3657-42,74-96
36681-98,38-98
36716-24,17-23
36895-97,32-96
36923-38,23-37
37042-54,40-46
37116-18,13-17
3721-81,3-63
37316-17,17-50
37482-87,88-97
3756-47,5-48
3768-81,92-94
37795-97,11-96
37823-94,22-86
3796-35,3-56
3807-93,90-92
3816-49,3-6
38224-86,86-86
38367-78,67-78
38411-98,10-96
38587-88,17-88
3868-98,99-99
38715-73,72-73
3881-60,60-60
38939-45,33-45
39077-95,41-76
3915-23,24-99
39296-98,97-97
39318-55,55-56
39497-98,60-90
39533-34,13-34
3967-96,8-96
3977-32,46-61
39875-93,20-96
39930-99,29-31
4004-99,3-97
4013-30,29-30
40240-40,39-63
40348-49,48-60
40422-24,6-22
40528-28,3-28
40664-64,37-63
40729-48,5-48
40820-37,19-36
40977-77,19-77
41018-85,2-19
41199-99,30-80
41235-36,31-35
41328-79,75-98
41426-94,26-95
41522-97,73-96
41642-42,5-41
4176-8,7-99
41810-14,13-14
41939-72,39-73
42012-90,89-90
42193-94,12-94
42250-88,89-93
42347-88,88-89
42439-64,38-38
42515-79,78-79
42628-32,32-33
42750-65,51-51
4287-79,6-64
42933-49,32-34
43082-95,75-96
4316-14,4-9
43295-95,10-96
43314-51,3-15
43497-98,21-98
43539-61,53-61
43668-69,37-68
43715-73,73-95
43842-70,43-83
4391-60,60-61
4406-11,11-94
44110-79,87-93
44236-40,41-41
4433-17,3-43
4444-81,4-82
44590-91,6-90
4462-3,5-68
44720-98,74-97
4484-86,3-85
44947-49,23-48
45026-89,26-90
45131-42,42-47
45257-81,39-58
45317-87,18-96
4549-77,9-78
45579-88,80-84
45630-84,83-83
45715-89,15-88
45811-11,10-94
45959-82,27-59
4608-78,14-33
46146-95,85-94
46293-97,92-94
4634-34,2-3
46434-80,30-82
46548-83,27-49
46647-99,47-48
46727-51,51-56
46848-49,35-48
46931-51,42-51
47096-97,19-96
47143-44,20-44
47276-76,13-75
4735-90,27-90
47426-27,27-51
47547-54,49-95
47669-72,4-73
47794-98,68-95
4781-2,3-86
47925-90,24-26
48028-90,89-89
48191-91,74-91
48256-95,40-57
48355-92,28-54
48428-34,27-35
48585-87,28-86
4868-10,10-98
48745-45,44-44
48831-83,27-59
48967-84,2-68
49017-69,51-69
49149-52,34-53
49222-81,2-23
49395-96,2-96
49482-99,17-82
49540-57,40-58
4969-40,40-40
4971-2,3-68
4981-97,90-97
4992-20,21-34
5002-2,1-92
50184-86,2-86
5027-92,97-99
5032-6,5-42
5041-52,1-52
50598-99,1-98
50638-80,29-43
50739-69,39-39
50897-99,3-98
50970-71,8-71
51026-52,25-38
5118-92,91-92
51212-49,13-27
5137-95,94-95
51491-99,15-92
51519-45,18-19
51675-76,76-97
51759-74,13-86
5183-3,2-3
51941-60,53-59
52075-99,29-96
52166-68,18-67
5223-91,3-95
52333-98,32-34
5245-78,10-77
52555-95,54-59
5266-81,6-81
52778-94,52-75
52820-93,10-94
52912-37,83-99
53046-93,92-99
53117-79,8-94
53245-99,46-46
53373-90,68-73
53482-83,58-83
53515-88,90-94
53666-96,18-65
53712-87,61-86
53835-85,36-84
53996-96,28-95
54082-95,2-83
5411-2,2-99
54259-88,59-60
54354-90,53-74
54435-48,57-57
54516-28,16-29
54635-45,36-36
54725-39,24-58
54819-74,27-75
54935-73,31-36
55016-76,6-87
5518-99,7-97
5521-1,1-89
5539-74,10-75
55412-74,11-56
55580-81,2-80
55613-97,19-92
55743-83,82-89
55855-59,60-60
55920-79,98-98
56061-62,61-86
56135-82,93-97
56221-42,43-43
56349-94,43-50
5645-81,98-99
5655-95,1-95
5666-80,91-97
56726-85,11-25
56834-68,19-48
5693-99,3-87
57081-81,19-81
5718-47,8-48
57246-70,46-71
57313-73,46-73
57413-83,14-82
5756-97,96-99
57619-33,18-34
57730-99,2-99
57850-84,1-84
5796-97,6-96
58096-96,6-96
58110-96,9-94
58238-39,38-43
58318-94,19-97
58486-86,87-91
5858-98,8-97
58684-86,78-85
58723-71,72-72
5885-99,98-98
58926-75,26-75
59087-87,20-88
59111-85,7-8
59252-61,45-62
59342-97,42-97
59425-89,21-24
59595-96,4-93
59666-69,67-68
5972-93,94-96
5988-9,9-81
59972-97,21-98
60059-75,58-60
60114-16,15-96
60271-71,70-71
60310-79,3-10
60454-54,53-98
6052-4,3-69
60614-66,14-67
60716-17,16-65
60827-99,76-99
60919-94,95-97
6103-83,83-84
61136-57,31-56
61234-83,33-83
61356-67,66-88
61430-70,17-31
61524-80,79-80
61643-52,42-43
61710-65,66-68
61850-69,1-70
61910-10,10-33
62010-99,9-98
62186-96,85-85
62230-65,31-60
62318-81,17-19
62412-84,49-71
62519-98,18-18
6263-67,4-68
62788-99,69-99
62811-87,10-11
62998-98,37-85
6308-90,47-89
6312-43,67-79
6325-5,4-97
63331-94,93-96
63413-83,14-14
63572-85,71-84
63651-53,26-52
6373-58,57-62
63841-58,41-58
63929-84,30-56
64089-98,21-90
64151-97,50-94
6428-96,8-95
6431-4,4-81
64423-51,52-95
64529-61,8-60
64611-15,1-5
6472-75,7-75
64842-66,46-66
64953-93,53-94
6505-99,3-6
6512-5,6-13
65265-97,46-99
65351-72,50-90
65436-65,64-66
6551-4,4-94
6567-8,7-86
6574-89,3-90
65861-98,60-62
65940-81,19-81
66028-73,27-73
6614-98,6-97
66263-73,63-89
66313-97,96-98
6645-13,13-88
66524-92,7-92
66615-31,14-28
6672-88,97-97
66811-45,11-45
66940-82,82-82
67051-51,50-60
67184-91,21-83
67271-98,71-97
67321-95,31-94
6741-97,1-41
6752-3,2-84
6763-4,4-91
67798-98,17-97
67815-15,16-84
67943-48,11-37
68013-83,11-15
68188-96,3-96
68255-91,24-55
6834-96,96-99
68466-82,80-80
6853-61,62-93
68699-99,11-70
68756-56,57-59
68840-40,39-99
68957-58,35-58
69036-95,94-94
6912-63,64-81
69218-24,24-62
69363-98,12-63
69481-81,18-80
69519-61,19-20
69611-18,11-22
6979-14,9-11
6986-7,6-85
69941-51,41-41
70018-43,17-19
7018-70,71-84
70276-76,11-75
70387-88,9-88
70455-73,54-56
70556-57,57-68
7064-11,11-88
7078-81,11-80
70825-70,71-71
70922-45,23-48
71014-84,5-95
71158-68,47-58
71217-66,38-66
71358-89,88-89
7147-28,14-27
71531-87,22-63
71692-96,39-91
71714-41,14-14
71862-65,3-61
71948-66,48-66
7204-95,2-96
7217-7,8-77
72217-50,18-51
72380-89,14-79
72428-50,28-89
72532-40,7-40
72619-77,18-19
72734-60,1-6
72833-50,51-91
72916-17,16-54
73029-45,19-32
73136-42,37-37
7321-95,3-87
73370-93,92-98
7344-11,46-79
73520-82,1-19
73640-41,2-42
73775-77,31-76
7388-14,14-78
73969-91,68-69
7409-63,77-89
74147-70,39-47
7423-98,97-98
74384-84,30-84
7449-9,10-95
74524-24,23-92
74627-95,21-95
7472-99,2-99
74838-59,54-59
74920-81,15-82
7506-73,13-73
75198-98,99-99
75218-92,17-19
75393-94,5-93
75413-99,13-14
75534-34,34-79
75612-88,87-96
75755-67,83-89
7586-30,1-31
75924-80,24-80
7605-90,16-91
76149-68,10-49
76211-14,13-92
76323-85,24-92
76467-81,67-68
76532-99,32-89
76685-86,35-84
76721-21,20-60
76825-85,25-84
76920-56,21-21
7706-9,9-71
77182-98,26-81
77237-37,15-38
7735-97,3-5
77411-18,19-26
77514-69,6-83
77651-73,50-75
77729-85,19-28
7788-59,5-60
77992-92,46-93
7808-57,7-9
78116-16,16-84
78210-32,10-11
7831-86,1-86
78426-98,19-91
7857-97,6-94
78641-81,42-80
7873-97,13-98
78824-25,24-87
78954-54,18-55
79049-49,33-50
7916-80,79-80
79238-95,38-95
79352-84,52-77
7946-92,1-6
7951-3,3-88
7966-71,2-5
79716-46,2-17
79879-86,15-80
7996-6,5-54
8008-41,11-40
80153-98,52-54
8022-79,1-3
80351-70,50-52
80455-55,56-69
8054-61,10-97
80675-92,12-76
80727-79,92-94
8086-55,5-7
80919-25,20-22
81079-92,65-93
81195-99,27-94
81223-88,23-88
81382-83,83-96
8142-94,2-74
81514-71,6-14
8166-14,5-7
8173-89,1-2
81848-82,13-26
81948-80,26-48
82043-93,92-92
82132-51,85-91
8223-5,5-90
82399-99,95-97
82438-39,38-88
82593-95,75-94
82615-64,14-16
82784-94,67-90
82822-47,48-80
82941-56,5-57
8302-80,7-79
83122-71,21-23
83221-49,20-22
83395-95,61-95
83456-57,57-58
83525-27,26-62
83652-76,41-61
83728-98,71-98
83874-93,4-93
83935-74,73-98
8404-57,3-57
8414-99,32-98
8428-75,7-75
84323-67,23-68
84415-15,15-56
8453-97,1-98
84610-90,91-91
84718-30,17-19
84810-38,1-90
84950-73,37-73
85040-91,92-95
85139-39,40-91
85286-87,7-87
85312-37,37-94
85478-87,14-50
85589-95,11-90
85660-98,4-94
85741-82,81-98
85866-92,67-67
85988-92,5-89
86086-91,85-86
8616-98,97-97
86234-87,95-95
86344-46,45-78
8647-87,17-87
8657-96,95-97
86615-75,76-85
8671-98,2-93
8683-55,50-54
86987-94,72-86
87019-70,19-63
8717-51,50-79
8723-73,3-73
87332-38,31-34
8742-99,98-98
8753-4,5-88
87616-37,38-38
87739-48,40-42
87865-77,65-77
8795-94,3-96
88028-89,97-98
88134-77,53-77
88224-54,25-28
8836-48,7-7
8846-38,3-6
88510-83,9-11
88626-65,64-84
88750-85,84-86
88836-91,37-92
8892-2,2-84
8904-6,5-83
89118-71,35-70
8925-85,5-64
89394-99,13-95
8941-32,2-9
89511-71,53-98
89699-99,18-97
89726-46,22-27
89839-78,91-93
89938-43,38-44
90014-76,15-54
90191-95,23-90
9027-55,3-55
90391-95,29-92
90410-23,9-59
90521-67,20-66
90617-27,20-26
9072-94,1-94
90816-97,13-97
90967-68,67-94
91081-83,27-82
91151-69,81-96
91279-81,57-80
91355-55,55-68
91434-96,34-95
91583-85,19-84
9164-81,3-80
91716-23,23-97
91845-74,46-74
9192-98,98-99
92037-59,35-59
92172-74,70-74
92216-91,91-92
92343-68,44-75
9244-77,7-92
92593-94,6-94
92618-92,93-94
92751-76,76-76
92817-42,41-79
92961-62,49-61
93019-77,9-9
93111-70,43-69
93221-62,53-61
93340-77,78-89
93410-55,10-46
9355-70,98-99
93619-21,20-86
9377-68,10-67
9382-24,3-3
93965-70,46-66
9401-78,2-77
94171-95,17-72
94225-88,88-89
94313-98,14-14
9447-81,7-8
9458-99,8-98
94613-97,14-97
9473-56,3-4
94889-99,29-73
94941-50,28-51
95076-88,76-87
95182-96,25-31
95230-41,8-42
95327-39,38-38
95446-71,46-71
95523-88,10-88
95628-83,28-84
95782-94,81-86
95899-99,1-99
9594-46,4-63
9607-68,67-99
9615-92,93-97
96291-95,3-89
96357-76,3-70
9641-89,53-88
9654-32,6-31
96675-76,2-76
96717-17,18-37
96843-90,89-94
9694-65,1-66
97088-91,90-91
97143-57,44-84
9722-95,2-94
9733-31,1-32
97412-94,30-93
97512-94,5-94
97635-54,34-54
97730-81,30-30
97851-53,52-98
97968-97,41-69
98032-94,19-31
98114-70,7-15
9821-99,41-98
98341-63,41-63
98488-88,27-87
98554-56,53-55
98626-26,27-71
98729-64,1-62
9884-54,1-92
98988-89,22-89
99015-88,15-16
99121-95,43-96
99212-13,12-27
99310-96,23-96
99482-83,22-83
99513-85,13-86
99677-83,4-65
9973-91,3-63
99873-98,73-98
99949-49,8-50
10003-96,4-4
diff --git a/day4/solution.nim b/day4/solution.nim
deleted file mode 100644
index 8085445..0000000
--- a/day4/solution.nim
+++ /dev/null
@@ -1,42 +0,0 @@
1import std/strutils
2import std/sequtils
3import std/sugar
4
5type
6 # We use begin and length for Range representation to simplify calculations later
7 Range = tuple[begin: int, length: int]
8 Entry = tuple[first: Range, second: Range]
9
10proc solve(entries: seq[Entry], part2 = false): int =
11 var score = 0
12 for e in entries:
13 var r: Entry
14 # Let first become the leftmost range. In case both ranges start at the same index, we consider the longest one to be first
15 if e.first.begin < e.second.begin or (e.first.begin == e.second.begin and e.first.length >= e.second.length):
16 r.first = e.first
17 r.second = e.second
18 else:
19 r.first = e.second
20 r.second = e.first
21
22 if not part2:
23 if r.first.length >= r.second.length + r.second.begin - r.first.begin:
24 score += 1
25 else:
26 if r.first.begin + r.first.length - 1 >= r.second.begin:
27 score += 1
28
29 return score
30
31func entryFromLine(line: string): Entry =
32 # Get tokens and parse them as integers
33 let tokens = map(line.split({',', '-'}), token => token.parseInt())
34 # Init Entry
35 ((tokens[0], tokens[1] - tokens[0]+1), (tokens[2], tokens[3] - tokens[2]+1))
36
37let
38 content = readFile("./input.txt").strip().splitLines()
39 entries = map(content, entryFromLine)
40
41echo solve(entries)
42echo solve(entries, true)