summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShivesh Mandalia <mail@shivesh.org>2023-02-05 01:32:03 +0000
committerShivesh Mandalia <mail@shivesh.org>2023-02-05 01:32:03 +0000
commit4cb3fa6de434d287bb46ca94c3026880164cb774 (patch)
tree38be4bcf69883777d7243b1d732c4ee8f184df30
parent21c330dcd6f9b873a37e04487a24ac21606c3aee (diff)
downloadAOC_2022_haskell-4cb3fa6de434d287bb46ca94c3026880164cb774.tar.gz
AOC_2022_haskell-4cb3fa6de434d287bb46ca94c3026880164cb774.zip
complete day 6 and 7
-rw-r--r--cabal.project2
-rw-r--r--day04/examples/input.txt1000
-rw-r--r--day04/examples/test.txt6
-rw-r--r--day05/app/Main.hs235
-rw-r--r--day05/day05.cabal34
-rw-r--r--day05/examples/input.txt513
-rw-r--r--day05/examples/test.txt9
-rw-r--r--day06/app/Main.hs154
-rw-r--r--day06/day06.cabal35
-rw-r--r--day06/examples/input.txt1
-rw-r--r--day06/examples/test0.txt1
-rw-r--r--day06/examples/test1.txt1
-rw-r--r--day06/examples/test2.txt1
-rw-r--r--day06/examples/test3.txt1
-rw-r--r--day06/examples/test4.txt1
-rw-r--r--day07/app/Main.hs259
-rw-r--r--day07/day07.cabal35
-rw-r--r--day07/examples/input.txt979
-rw-r--r--day07/examples/test.txt23
19 files changed, 2283 insertions, 1007 deletions
diff --git a/cabal.project b/cabal.project
index 63f8a15..6a0c239 100644
--- a/cabal.project
+++ b/cabal.project
@@ -1,2 +1,2 @@
-- Local packages
-packages: day01, day02, day03, day04
+packages: day01, day02, day03, day04, day05, day06, day07
diff --git a/day04/examples/input.txt b/day04/examples/input.txt
deleted file mode 100644
index bab3d4d..0000000
--- a/day04/examples/input.txt
+++ /dev/null
@@ -1,1000 +0,0 @@
-14-50,14-50
-43-44,43-87
-55-99,51-96
-67-68,68-91
-8-8,27-73
-22-92,21-92
-4-80,3-80
-10-67,34-67
-49-56,49-89
-27-96,27-28
-30-47,29-47
-75-75,16-74
-50-70,47-63
-9-89,10-88
-1-69,16-68
-9-76,52-76
-4-96,98-98
-28-66,11-29
-47-60,46-47
-37-88,36-88
-37-98,37-99
-9-88,87-88
-2-8,2-3
-29-98,29-46
-12-98,12-83
-85-99,19-98
-5-37,37-37
-52-99,52-99
-50-76,27-75
-57-59,29-58
-6-71,71-74
-61-77,62-77
-76-76,16-75
-3-27,4-27
-1-2,1-46
-4-74,4-73
-71-99,13-70
-29-92,30-92
-59-59,58-58
-49-54,50-51
-3-85,69-86
-26-76,66-66
-14-97,9-97
-43-44,7-45
-54-54,37-54
-2-91,4-68
-43-84,78-83
-4-97,3-97
-8-42,13-97
-26-95,2-16
-25-68,25-68
-4-57,3-62
-23-85,23-24
-68-78,32-74
-27-70,34-70
-6-70,69-71
-54-56,5-55
-21-54,21-54
-8-85,7-8
-46-57,45-63
-77-79,26-78
-9-37,8-37
-7-66,66-67
-76-93,93-93
-20-73,21-74
-12-13,12-14
-77-97,77-97
-12-92,13-13
-85-85,82-86
-80-91,18-74
-1-96,1-99
-29-31,30-30
-78-94,77-77
-32-45,3-58
-15-76,15-76
-49-73,73-97
-12-73,19-73
-95-95,22-94
-13-67,13-19
-4-5,6-99
-60-62,4-61
-16-54,16-55
-88-92,90-93
-33-40,40-86
-72-94,49-71
-4-94,5-48
-1-37,1-37
-18-84,83-84
-64-77,77-78
-93-93,92-93
-25-94,95-95
-10-41,6-41
-66-89,69-86
-21-97,22-97
-60-74,2-60
-39-60,54-59
-29-74,73-73
-44-61,43-61
-10-80,11-80
-79-80,4-83
-3-7,8-98
-40-47,48-68
-73-85,73-86
-72-85,73-85
-3-95,94-99
-63-64,11-64
-41-60,36-42
-2-45,6-10
-42-45,41-58
-9-77,73-75
-48-55,13-54
-23-33,23-24
-92-92,16-91
-83-97,84-97
-93-97,2-94
-34-80,33-62
-37-92,87-93
-67-67,32-67
-1-72,7-71
-57-85,86-88
-53-56,50-53
-97-99,3-98
-3-6,8-93
-22-81,22-99
-53-77,53-53
-97-99,3-98
-35-55,35-55
-30-30,30-95
-27-94,28-37
-30-68,57-79
-30-84,83-85
-16-22,14-21
-95-95,2-95
-34-45,35-51
-16-36,12-17
-3-3,3-95
-8-77,6-78
-4-89,6-86
-77-83,76-88
-43-43,37-42
-41-62,44-97
-67-86,85-87
-82-96,99-99
-75-92,80-83
-12-29,12-29
-82-94,18-81
-9-93,97-97
-83-93,79-84
-90-97,17-90
-29-32,22-31
-14-48,3-81
-72-84,63-84
-7-98,6-97
-6-83,6-82
-6-83,58-93
-2-62,11-80
-77-77,76-82
-36-37,36-60
-1-84,7-83
-10-48,32-72
-2-51,25-48
-22-96,18-99
-99-99,55-95
-5-59,1-60
-65-70,4-69
-10-91,10-90
-6-98,1-7
-83-90,88-91
-39-39,24-38
-34-87,4-35
-86-88,15-85
-44-52,43-44
-1-81,53-99
-85-88,85-99
-87-87,63-87
-96-99,1-96
-20-22,21-23
-32-57,33-56
-4-89,4-90
-16-81,17-52
-83-99,16-84
-14-21,15-16
-38-80,79-86
-60-81,59-99
-90-93,15-89
-2-74,75-78
-3-91,18-67
-22-91,22-22
-16-19,18-83
-9-81,10-91
-2-98,2-49
-93-94,77-94
-28-92,11-93
-36-99,36-97
-32-48,48-48
-11-14,15-71
-5-81,5-56
-23-61,23-24
-92-94,23-93
-3-40,7-98
-28-98,99-99
-2-62,50-63
-20-43,18-18
-38-51,50-51
-3-11,37-46
-8-95,2-7
-96-98,23-73
-73-92,73-73
-96-99,1-97
-2-83,83-88
-12-73,99-99
-13-86,12-87
-87-87,23-87
-95-96,40-71
-18-42,18-92
-29-61,23-62
-59-97,58-93
-35-74,34-75
-8-94,9-95
-15-65,76-82
-26-89,16-97
-53-71,11-85
-5-51,3-51
-21-43,22-76
-33-33,23-32
-10-29,9-30
-87-88,87-96
-2-50,3-51
-23-83,22-87
-15-96,95-97
-10-77,9-78
-67-95,67-95
-17-18,18-64
-2-9,8-83
-8-51,50-51
-92-92,2-92
-6-16,5-15
-32-47,37-49
-15-81,75-96
-34-75,49-71
-6-71,6-71
-15-92,91-92
-43-91,43-91
-50-78,49-77
-35-56,55-55
-45-77,76-77
-9-76,9-91
-7-88,7-88
-51-72,50-51
-21-98,7-44
-35-89,35-89
-17-87,4-87
-60-75,61-61
-92-96,45-93
-47-59,46-58
-4-97,1-28
-38-39,37-39
-9-63,24-84
-8-94,14-93
-49-86,58-85
-10-13,8-42
-98-98,41-93
-25-75,26-92
-5-80,79-81
-6-56,23-56
-17-94,94-94
-87-87,34-87
-55-57,55-69
-48-80,37-47
-99-99,2-99
-38-57,37-56
-63-86,62-86
-97-97,24-98
-18-61,17-60
-10-68,6-42
-86-86,11-86
-9-24,24-24
-17-73,72-72
-12-97,13-98
-5-83,29-84
-5-45,79-95
-36-36,51-86
-3-63,2-86
-1-65,17-36
-7-7,6-9
-5-5,5-99
-8-48,7-46
-3-83,1-84
-28-76,29-77
-65-94,3-95
-14-53,15-50
-1-29,15-41
-9-86,9-94
-30-97,29-48
-74-86,78-83
-2-17,3-17
-83-83,29-82
-16-76,96-96
-3-63,4-63
-2-98,2-98
-15-98,14-97
-2-13,14-62
-31-76,75-77
-97-97,28-98
-87-87,82-87
-37-45,38-46
-17-39,21-42
-23-67,43-62
-3-43,3-4
-67-91,67-80
-10-91,10-11
-1-97,6-97
-29-97,99-99
-78-78,18-77
-5-98,6-98
-49-86,87-96
-6-84,7-7
-1-92,1-92
-33-51,24-32
-15-85,2-86
-67-86,67-92
-4-78,6-90
-15-92,8-92
-12-93,94-99
-12-67,32-96
-73-95,74-96
-35-45,35-42
-68-69,67-77
-16-70,7-16
-84-86,21-85
-12-19,5-18
-82-94,94-95
-8-27,28-28
-55-93,11-93
-31-86,98-99
-41-65,41-64
-56-76,31-57
-15-41,7-41
-92-94,7-93
-5-24,25-39
-5-25,24-24
-3-3,3-20
-52-92,91-91
-16-94,16-95
-3-85,1-86
-38-90,38-90
-35-36,35-98
-7-18,7-8
-12-35,12-36
-6-89,31-33
-37-56,40-67
-1-98,1-99
-2-96,2-99
-13-49,13-19
-9-99,51-77
-3-87,74-88
-69-69,17-69
-39-98,38-43
-20-42,19-57
-57-99,35-56
-90-98,89-89
-9-71,8-70
-5-72,5-38
-37-91,4-37
-46-87,10-93
-9-78,8-77
-58-58,11-59
-8-13,14-95
-76-84,75-83
-27-77,1-27
-17-96,14-55
-50-55,33-55
-86-99,86-92
-58-81,81-81
-88-88,70-88
-36-36,18-36
-57-59,11-58
-5-6,6-15
-94-97,39-94
-27-63,27-80
-35-57,36-58
-4-83,8-83
-84-91,15-64
-10-43,44-79
-51-51,16-51
-4-97,5-98
-10-36,22-29
-3-90,56-87
-63-90,83-98
-53-75,52-74
-89-96,29-88
-66-99,21-98
-14-19,19-86
-27-27,26-65
-75-82,18-76
-11-95,94-98
-77-78,78-90
-13-15,14-72
-11-88,25-88
-23-23,22-46
-32-41,33-78
-54-90,39-60
-14-71,15-68
-3-95,95-95
-29-73,72-73
-20-33,20-33
-33-61,33-85
-15-92,15-95
-7-77,43-68
-50-55,54-55
-38-65,38-64
-43-68,54-77
-15-58,15-51
-2-38,3-46
-36-36,36-73
-9-70,10-71
-79-83,82-88
-55-86,55-55
-19-57,18-60
-26-31,27-76
-14-66,3-13
-94-97,2-95
-10-98,21-94
-20-44,21-44
-47-99,46-99
-13-31,21-24
-1-99,99-99
-17-92,53-93
-54-74,53-74
-8-16,16-98
-10-98,10-99
-18-67,68-89
-38-77,76-85
-26-66,25-67
-9-35,35-94
-10-43,11-44
-69-92,4-38
-48-84,15-49
-5-50,23-51
-9-27,27-71
-21-99,21-21
-4-97,97-99
-41-53,2-52
-11-66,2-57
-32-75,16-31
-7-59,6-58
-45-97,93-96
-14-71,10-71
-50-98,37-49
-29-76,77-77
-78-80,79-80
-23-30,22-30
-4-5,4-98
-17-35,35-36
-16-42,42-43
-50-92,19-51
-29-57,29-56
-27-75,3-80
-10-62,62-62
-48-76,24-49
-71-73,2-72
-38-42,40-41
-24-74,25-30
-4-22,1-21
-6-47,6-46
-31-36,31-85
-6-98,8-98
-98-99,52-98
-34-90,49-91
-44-88,45-89
-33-94,94-95
-6-91,3-6
-6-8,5-87
-8-97,75-98
-45-75,94-94
-60-80,60-99
-97-97,30-98
-15-16,15-79
-40-67,63-96
-24-94,22-93
-6-57,8-57
-8-97,97-97
-83-83,44-78
-13-17,20-95
-8-56,56-87
-7-96,1-96
-21-88,22-82
-2-44,2-44
-10-93,14-66
-10-98,10-82
-4-55,1-1
-4-5,4-98
-21-29,28-29
-67-82,24-33
-26-99,26-27
-46-74,73-74
-83-83,71-83
-33-52,23-53
-53-89,30-52
-35-67,51-67
-24-87,86-98
-21-96,21-64
-92-93,30-92
-32-41,41-94
-99-99,6-97
-98-99,4-95
-3-74,2-74
-50-50,20-51
-4-19,18-18
-8-94,3-95
-23-84,59-65
-34-75,74-74
-57-92,17-94
-40-42,41-84
-29-62,29-97
-94-97,99-99
-66-70,66-71
-98-99,22-99
-26-72,26-55
-11-66,11-94
-8-91,8-87
-50-74,44-88
-71-76,71-72
-1-65,1-65
-61-89,1-88
-8-12,8-15
-92-94,14-92
-4-95,1-95
-24-96,24-90
-34-75,27-74
-13-77,18-94
-21-89,13-90
-10-96,9-10
-43-56,24-56
-9-14,9-10
-3-95,31-95
-36-52,43-46
-29-44,44-96
-20-96,13-97
-45-78,36-84
-8-72,9-72
-96-99,42-97
-14-75,76-76
-48-71,61-72
-18-78,17-77
-4-37,2-2
-9-98,4-8
-29-51,49-52
-67-80,52-80
-24-24,22-57
-11-80,11-80
-19-22,79-86
-47-87,47-87
-58-70,58-71
-44-67,44-54
-2-63,2-96
-8-28,7-70
-3-20,20-21
-35-69,69-95
-2-18,1-18
-4-92,91-93
-31-70,31-71
-46-48,11-47
-75-77,23-76
-78-78,24-77
-8-71,8-13
-19-85,26-73
-64-82,88-99
-30-74,4-74
-3-15,1-15
-44-57,43-45
-36-99,35-96
-14-84,8-84
-2-84,11-80
-19-36,37-37
-38-61,60-85
-28-76,27-29
-63-65,52-64
-84-86,1-85
-45-45,9-45
-5-71,3-96
-42-44,35-45
-41-72,41-73
-4-62,2-51
-14-29,14-29
-10-11,11-91
-95-95,1-96
-6-80,5-78
-31-68,69-87
-5-80,80-81
-5-91,8-68
-15-86,98-99
-49-88,49-84
-4-15,16-73
-31-79,64-65
-85-85,5-85
-21-47,17-20
-13-87,25-78
-94-94,1-93
-4-96,3-96
-22-61,6-61
-3-85,2-80
-16-17,17-66
-23-67,67-67
-13-83,55-83
-97-97,63-98
-17-62,17-17
-43-61,44-80
-47-56,52-59
-48-87,87-96
-49-50,75-88
-5-95,5-95
-5-72,7-71
-16-51,50-51
-25-80,11-79
-23-91,24-91
-94-96,48-95
-17-99,17-17
-3-68,67-68
-15-84,9-85
-29-87,26-87
-88-91,87-96
-6-70,69-70
-40-58,34-43
-19-98,39-98
-3-96,3-95
-38-86,85-88
-32-71,47-63
-62-88,14-99
-24-54,94-95
-14-26,15-15
-29-86,19-87
-7-83,10-84
-4-95,96-96
-45-55,45-54
-9-71,27-93
-27-85,45-85
-32-79,2-77
-34-79,20-78
-8-20,12-20
-5-6,6-91
-14-34,14-35
-19-67,73-74
-5-95,5-96
-23-96,3-23
-30-51,15-52
-39-52,35-51
-45-45,28-44
-8-15,16-16
-3-90,2-75
-36-84,36-84
-86-97,86-97
-20-93,67-92
-18-43,16-90
-1-12,13-98
-12-93,11-50
-15-79,15-93
-77-82,59-78
-31-92,32-93
-27-79,28-90
-4-76,32-85
-26-46,45-45
-85-89,85-96
-28-43,28-95
-37-97,20-96
-2-64,64-64
-46-51,47-87
-82-88,7-82
-14-48,44-46
-25-99,25-25
-31-31,30-71
-23-89,88-90
-55-83,38-92
-19-67,11-68
-16-32,17-71
-59-79,79-81
-28-95,23-28
-86-96,11-87
-20-46,31-49
-5-6,5-49
-15-79,15-90
-95-97,3-96
-17-19,18-57
-56-82,57-98
-92-92,47-91
-88-89,89-91
-97-98,6-96
-7-89,8-63
-49-85,2-50
-74-75,62-75
-14-35,15-35
-11-64,5-46
-2-6,5-83
-58-95,28-81
-28-73,29-29
-84-93,30-83
-41-97,97-98
-22-48,22-48
-54-90,76-90
-88-99,8-89
-67-94,68-68
-51-55,51-90
-40-58,44-89
-60-78,60-77
-23-69,23-85
-34-85,35-86
-87-99,16-75
-34-96,96-98
-39-72,12-72
-25-92,92-94
-8-73,73-82
-12-92,13-95
-30-92,55-98
-37-37,10-38
-31-38,34-34
-54-88,2-85
-12-42,41-41
-5-97,96-97
-82-82,20-83
-3-24,1-24
-20-96,96-96
-33-99,34-54
-26-93,26-37
-21-58,21-58
-61-86,2-47
-5-65,4-98
-2-66,2-99
-64-66,15-65
-11-75,2-58
-55-75,47-93
-37-58,36-58
-21-71,21-71
-45-92,40-58
-18-40,37-43
-33-65,33-65
-43-84,91-93
-13-13,13-80
-30-84,31-72
-38-98,39-98
-42-88,91-98
-10-91,9-10
-56-66,67-94
-55-87,54-78
-9-96,9-95
-18-63,7-64
-9-28,27-29
-32-67,16-68
-1-9,15-45
-34-44,34-80
-98-98,89-99
-9-68,10-96
-42-43,26-43
-82-90,91-93
-21-21,11-21
-7-58,5-95
-93-95,60-93
-7-40,8-94
-25-26,26-96
-8-98,7-98
-23-87,24-87
-9-51,10-48
-21-99,18-98
-32-79,7-55
-2-99,1-99
-11-85,3-85
-2-85,1-85
-21-83,59-70
-33-33,32-34
-21-60,22-43
-14-29,14-28
-35-55,34-54
-50-59,50-50
-39-68,67-85
-14-21,6-79
-26-47,47-87
-2-82,82-89
-46-55,46-47
-6-86,87-87
-60-60,8-64
-27-28,28-79
-1-2,1-98
-11-85,84-89
-12-27,20-21
-6-93,9-90
-6-92,2-98
-77-86,25-76
-37-62,79-82
-69-97,36-96
-7-92,99-99
-73-73,32-74
-92-97,62-95
-41-96,51-96
-22-97,34-96
-25-26,26-50
-11-86,12-87
-68-84,4-82
-14-87,46-86
-28-30,29-68
-1-68,2-45
-6-92,5-94
-2-28,36-77
-5-11,5-24
-35-91,29-91
-40-93,7-94
-70-96,10-69
-67-96,10-66
-67-67,67-67
-1-63,3-63
-9-95,8-95
-78-78,37-79
-47-48,47-79
-14-93,14-14
-24-96,31-96
-29-29,6-30
-60-67,60-67
-80-80,2-81
-24-85,30-84
-66-73,72-82
-58-97,59-97
-9-9,9-95
-21-42,22-42
-5-35,3-6
-39-98,97-98
-85-96,44-97
-65-98,11-97
-2-94,2-95
-64-96,66-97
-2-99,2-95
-32-51,32-43
-4-11,11-40
-1-64,1-1
-89-96,19-88
-11-32,12-17
-5-98,5-98
-17-98,16-96
-18-71,17-98
-37-75,37-71
-37-92,37-92
-7-88,38-76
-3-13,12-52
-6-96,7-97
-91-99,2-90
-30-95,30-31
-9-27,9-59
-72-78,39-72
-23-30,27-84
-75-92,26-74
-30-36,31-35
-55-55,24-54
-32-71,32-33
-6-88,87-96
-16-97,15-96
-44-81,81-98
-63-92,40-64
-70-70,14-71
-33-59,34-36
-13-26,13-62
-64-86,2-85
-38-90,37-90
-71-80,16-81
-10-41,17-97
-11-74,10-74
-88-96,85-89
-3-64,1-65
-71-79,78-95
-25-39,25-40
-18-98,2-99
-42-43,43-66
-2-90,3-91
-8-86,86-94
-10-97,98-99
-3-99,13-51
-35-84,72-84
-26-27,13-27
-10-71,2-87
-71-82,72-80
-60-87,28-64
-58-79,44-78
-1-98,2-98
-28-99,26-50
-12-77,27-76
-5-57,56-56
-29-43,29-43
-41-86,10-41
-45-69,44-69
-14-91,15-91
-42-57,62-73
-24-30,24-26
-57-64,62-65
-14-47,14-15
-3-88,79-89
-2-4,4-80
-54-90,10-89
-6-47,6-47
-66-68,65-70
-82-85,9-84
-73-91,73-79
-83-96,16-82
-93-96,41-72
-6-41,40-81
-7-53,3-7
-85-96,84-89
-9-20,10-71
-25-44,43-45
-2-99,99-99
-7-95,8-96
-50-53,49-53
-9-26,10-26
-3-50,47-50
-40-59,60-60
-66-71,72-72
-3-74,1-75
-43-79,25-80
-29-30,29-31
-8-50,58-68
-41-96,42-96
-62-64,62-81
-4-88,5-88
-2-93,2-92
-57-58,58-88
-56-84,31-80
-90-91,4-90
-8-72,40-73
-41-76,41-53
-57-57,5-62
-20-40,19-39
-74-77,21-80
-1-64,4-97
-13-48,48-88
-21-28,4-28
-14-16,14-14
-9-24,5-25
-20-67,17-18
-66-81,67-98
-22-61,23-57
-31-67,66-67
-14-75,74-76
-12-95,13-97
-49-51,1-50
-1-74,12-75
-4-93,94-94
-76-80,98-99
-74-79,78-80
-35-79,22-80
-30-89,88-89
-31-77,31-94
-73-90,89-94
-7-83,7-98
-5-98,4-6
-4-99,96-98
-19-75,18-75
-9-99,9-99
-69-75,6-68
-48-69,47-85
-7-80,6-87
-28-35,7-99
-59-60,41-59
-28-64,27-64
-5-97,1-73
-33-88,89-94
-20-98,10-98
-9-12,10-83
-11-73,74-90
-28-86,85-87
-14-56,56-90
-47-98,46-98
-11-83,82-83
-16-46,45-47
-98-98,1-98
-32-72,33-41
-3-62,2-62
-47-48,25-47
-12-46,5-46
-10-78,10-10
-18-95,4-94
-24-81,9-70
-6-98,90-97
-3-55,38-60
-55-68,55-67
-22-80,22-82
-6-70,7-7
-13-15,12-18
-54-95,38-89
-19-93,42-93
-65-92,93-97
-50-93,50-63
-50-99,50-99
-49-49,3-48
-4-54,4-54
-48-49,49-80
-1-4,3-3
-66-98,17-67
-56-70,55-93
-51-95,51-51
-64-73,37-65
-21-72,37-76
-45-73,46-73
-35-38,36-39
-17-36,17-37
-98-98,17-99
diff --git a/day04/examples/test.txt b/day04/examples/test.txt
deleted file mode 100644
index 9f9e9cf..0000000
--- a/day04/examples/test.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-2-4,6-8
-2-3,4-5
-5-7,7-9
-2-8,3-7
-6-6,4-6
-2-6,4-8
diff --git a/day05/app/Main.hs b/day05/app/Main.hs
new file mode 100644
index 0000000..b56e45b
--- /dev/null
+++ b/day05/app/Main.hs
@@ -0,0 +1,235 @@
+{-
+--- Day 5: Supply Stacks ---
+
+The expedition can depart as soon as the final supplies have been unloaded from the
+ships. Supplies are stored in stacks of marked crates, but because the needed supplies are
+buried under many other crates, the crates need to be rearranged.
+
+The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of
+the crates get crushed or fall over, the crane operator will rearrange them in a series of
+carefully-planned steps. After the crates are rearranged, the desired crates will be at the
+top of each stack.
+
+The Elves don't want to interrupt the crane operator during this delicate procedure, but they
+forgot to ask her which crate will end up where, and they want to be ready to unload them as
+soon as possible so they can embark.
+
+They do, however, have a drawing of the starting stacks of crates and the rearrangement
+procedure (your puzzle input). For example:
+
+ [D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+
+move 1 from 2 to 1
+move 3 from 1 to 3
+move 2 from 2 to 1
+move 1 from 1 to 2
+
+In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on
+the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are
+crates M, C, and D. Finally, stack 3 contains a single crate, P.
+
+Then, the rearrangement procedure is given. In each step of the procedure, a quantity of
+crates is moved from one stack to a different stack. In the first step of the above
+rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this
+configuration:
+
+[D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+
+In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a
+time, so the first crate to be moved (D) ends up below the second and third crates:
+
+ [Z]
+ [N]
+ [C] [D]
+ [M] [P]
+ 1 2 3
+
+Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a
+time, crate C ends up below crate M:
+
+ [Z]
+ [N]
+[M] [D]
+[C] [P]
+ 1 2 3
+
+Finally, one crate is moved from stack 1 to stack 2:
+
+ [Z]
+ [N]
+ [D]
+[C] [M] [P]
+ 1 2 3
+
+The Elves just need to know which crate will end up on top of each stack; in this example, the
+top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these
+together and give the Elves the message CMZ.
+
+After the rearrangement procedure completes, what crate ends up on top of each stack?
+
+--- Part Two ---
+
+As you watch the crane operator expertly rearrange the crates, you notice the process isn't
+following your prediction.
+
+Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The
+crane isn't a CrateMover 9000 - it's a CrateMover 9001.
+
+The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather
+seats, an extra cup holder, and the ability to pick up and move multiple crates at once.
+
+Again considering the example above, the crates begin in the same configuration:
+
+```
+ [D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+```
+
+Moving a single crate from stack 2 to stack 1 behaves the same as before:
+
+```
+[D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+```
+
+However, the action of moving three crates from stack 1 to stack 3 means that those three moved
+crates stay in the same order, resulting in this new configuration:
+
+```
+ [D]
+ [N]
+ [C] [Z]
+ [M] [P]
+ 1 2 3
+```
+
+Next, as both crates are moved from stack 2 to stack 1, they retain their order as well:
+
+```
+ [D]
+ [N]
+[C] [Z]
+[M] [P]
+ 1 2 3
+```
+
+Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that gets moved:
+
+```
+ [D]
+ [N]
+ [Z]
+[M] [C] [P]
+ 1 2 3
+```
+
+In this example, the CrateMover 9001 has put the crates in a totally different order: MCD.
+
+Before the rearrangement process finishes, update your simulation so that the Elves know where
+they should stand to be ready to unload the final supplies. After the rearrangement procedure
+completes, what crate ends up on top of each stack?
+-}
+{-# LANGUAGE DerivingStrategies #-}
+
+module Main (main) where
+
+import Data.ByteString.Lazy (ByteString)
+import Data.Char (digitToInt)
+import Options.Applicative (Parser, ParserInfo, argument, execParser, fullDesc, help, helper, info, metavar, str)
+import Relude hiding (ByteString, elem, empty, filter, fromList, length, null, optional, readFile, splitAt)
+import Text.Parsec (ParseError, parse, (<?>))
+import Text.Parsec.ByteString.Lazy (GenParser)
+import Text.Parsec.Char (char, digit, string, upper)
+import Text.Parsec.Combinator (eof, many1, sepBy1, sepEndBy1)
+import Text.Parsec.Prim (parsecMap, try)
+
+type Opts :: Type
+newtype Opts = Opts {_filename :: Text} deriving stock (Show)
+
+type Supplies :: Type
+newtype Supplies = Supplies {_i :: [[Char]]} deriving stock (Show)
+
+type Order :: Type
+data Order = Order {_amount :: Int, _from :: Int, _to :: Int} deriving stock (Show)
+
+parseInput :: FilePath -> ByteString -> Either ParseError (Supplies, [Order])
+parseInput = parse $ (,) <$> (supplies <* eol) <*> orders
+ where
+ supplies :: GenParser t st Supplies
+ supplies = Supplies <$> many1 (lineBlock <* eol) <* axis
+
+ lineBlock :: GenParser t st [Char]
+ lineBlock = block `sepBy1` space
+
+ block :: GenParser t st Char
+ block = (char '[' *> upper <* char ']') <|> (' ' <$ try (string " "))
+
+ axis :: GenParser t st [()]
+ axis = void space *> (void int `sepEndBy1` spaces) <* eol
+
+ orders :: GenParser t st [Order]
+ orders = many1 order
+
+ order :: GenParser t st Order
+ order =
+ Order
+ <$> (string "move " *> int)
+ <*> (string " from " *> int)
+ <*> (string " to " *> int <* (eol <|> eof))
+
+ space :: GenParser t st Char
+ space = char ' '
+
+ spaces :: GenParser t st [Char]
+ spaces = many1 space
+
+ int :: GenParser t st Int
+ int = foldl' (\a i -> a * 10 + digitToInt i) 0 <$> many1 digit
+
+ eol :: GenParser t st ()
+ eol =
+ parsecMap
+ (const ())
+ ( try (string "\n\r")
+ <|> try (string "\r\n")
+ <|> string "\n"
+ <|> string "\r"
+ <?> "end of line"
+ )
+
+runPart1 :: (Supplies, [Order]) -> (Supplies, [Order])
+runPart1 x = x
+
+runPart2 :: (Supplies, [Order]) -> Int
+runPart2 = undefined
+
+main :: IO ()
+main = do
+ fileName <- toString . _filename <$> execParser opts
+ rawInput <- readFileLBS fileName
+ case parseInput fileName rawInput of
+ Left e -> do
+ putTextLn "Error parsing input:"
+ print e
+ Right r -> do
+ print $ runPart1 r
+ print $ runPart2 r
+ where
+ opts :: ParserInfo Opts
+ opts = info (helper <*> options) fullDesc
+
+ options :: Parser Opts
+ options = Opts <$> filename
+
+ filename :: Parser Text
+ filename = argument str $ metavar "filename" <> help "Input file"
diff --git a/day05/day05.cabal b/day05/day05.cabal
new file mode 100644
index 0000000..0923420
--- /dev/null
+++ b/day05/day05.cabal
@@ -0,0 +1,34 @@
+cabal-version: 2.4
+name: day05
+version: 0.1.0.0
+synopsis:
+
+-- A URL where users can report bugs.
+-- bug-reports:
+license:
+author: Shivesh Mandalia
+maintainer: mail@shivesh.org
+
+executable day05
+ main-is: Main.hs
+
+ -- Modules included in this executable, other than Main.
+ -- other-modules:
+
+ -- LANGUAGE extensions used by modules in this package.
+ default-extensions:
+ NoImplicitPrelude
+ OverloadedStrings
+ StandaloneKindSignatures
+
+ build-depends:
+ , base ^>=4.16.4.0
+ , optparse-applicative >=0.17.0.0
+ , parsec >=3.1.16.1
+ , relude ^>=1.1.0.0
+
+ hs-source-dirs: app
+ default-language: Haskell2010
+ ghc-options:
+ -Weverything -Wno-unused-packages -Wno-missing-safe-haskell-mode
+ -Wno-safe -Wno-missing-import-lists
diff --git a/day05/examples/input.txt b/day05/examples/input.txt
new file mode 100644
index 0000000..ca57552
--- /dev/null
+++ b/day05/examples/input.txt
@@ -0,0 +1,513 @@
+[C] [S] [H]
+[F] [B] [C] [S] [W]
+[B] [W] [W] [M] [S] [B]
+[L] [H] [G] [L] [P] [F] [Q]
+[D] [P] [J] [F] [T] [G] [M] [T]
+[P] [G] [B] [N] [L] [W] [P] [W] [R]
+[Z] [V] [W] [J] [J] [C] [T] [S] [C]
+[S] [N] [F] [G] [W] [B] [H] [F] [N]
+ 1 2 3 4 5 6 7 8 9
+
+move 2 from 5 to 9
+move 3 from 1 to 7
+move 2 from 3 to 9
+move 6 from 9 to 5
+move 2 from 3 to 8
+move 9 from 7 to 8
+move 15 from 8 to 9
+move 3 from 1 to 6
+move 6 from 4 to 2
+move 6 from 5 to 6
+move 1 from 4 to 2
+move 14 from 6 to 2
+move 2 from 1 to 5
+move 1 from 7 to 3
+move 1 from 4 to 8
+move 2 from 5 to 6
+move 25 from 2 to 4
+move 2 from 6 to 4
+move 1 from 8 to 1
+move 2 from 9 to 1
+move 1 from 6 to 1
+move 2 from 1 to 7
+move 1 from 7 to 3
+move 2 from 1 to 8
+move 1 from 2 to 6
+move 1 from 3 to 8
+move 4 from 5 to 6
+move 1 from 5 to 3
+move 1 from 9 to 6
+move 2 from 3 to 4
+move 1 from 2 to 6
+move 12 from 9 to 7
+move 1 from 9 to 1
+move 1 from 5 to 8
+move 1 from 3 to 8
+move 28 from 4 to 5
+move 1 from 4 to 3
+move 1 from 2 to 6
+move 1 from 3 to 9
+move 12 from 7 to 2
+move 1 from 9 to 6
+move 6 from 6 to 4
+move 1 from 7 to 4
+move 1 from 1 to 2
+move 28 from 5 to 1
+move 2 from 2 to 8
+move 3 from 8 to 2
+move 7 from 4 to 1
+move 4 from 8 to 6
+move 9 from 2 to 8
+move 7 from 6 to 5
+move 3 from 5 to 9
+move 1 from 9 to 7
+move 1 from 7 to 1
+move 5 from 8 to 4
+move 4 from 1 to 9
+move 6 from 9 to 4
+move 5 from 1 to 5
+move 5 from 2 to 3
+move 4 from 8 to 2
+move 5 from 1 to 4
+move 4 from 5 to 9
+move 9 from 4 to 9
+move 10 from 9 to 8
+move 1 from 9 to 1
+move 2 from 2 to 8
+move 4 from 3 to 8
+move 1 from 2 to 3
+move 2 from 9 to 2
+move 1 from 2 to 6
+move 4 from 4 to 3
+move 3 from 5 to 1
+move 12 from 1 to 4
+move 1 from 5 to 3
+move 1 from 5 to 3
+move 5 from 8 to 5
+move 7 from 8 to 5
+move 8 from 3 to 4
+move 1 from 5 to 1
+move 1 from 6 to 7
+move 2 from 1 to 6
+move 8 from 5 to 9
+move 2 from 5 to 1
+move 9 from 1 to 4
+move 20 from 4 to 2
+move 1 from 5 to 2
+move 4 from 4 to 2
+move 5 from 9 to 2
+move 2 from 8 to 9
+move 23 from 2 to 4
+move 2 from 2 to 5
+move 5 from 1 to 2
+move 28 from 4 to 3
+move 2 from 8 to 1
+move 2 from 5 to 7
+move 1 from 6 to 9
+move 1 from 4 to 8
+move 1 from 8 to 9
+move 1 from 4 to 6
+move 2 from 7 to 2
+move 13 from 3 to 4
+move 5 from 9 to 7
+move 1 from 9 to 6
+move 14 from 2 to 6
+move 1 from 4 to 1
+move 10 from 3 to 2
+move 1 from 6 to 9
+move 2 from 3 to 2
+move 3 from 1 to 9
+move 1 from 3 to 5
+move 3 from 9 to 3
+move 6 from 7 to 4
+move 1 from 9 to 4
+move 1 from 9 to 2
+move 1 from 5 to 3
+move 5 from 3 to 1
+move 17 from 4 to 7
+move 2 from 2 to 8
+move 1 from 3 to 9
+move 1 from 8 to 2
+move 1 from 9 to 6
+move 4 from 6 to 2
+move 10 from 6 to 5
+move 4 from 1 to 5
+move 15 from 2 to 9
+move 1 from 8 to 6
+move 1 from 2 to 8
+move 6 from 9 to 2
+move 3 from 4 to 8
+move 11 from 7 to 1
+move 6 from 9 to 6
+move 1 from 6 to 2
+move 3 from 9 to 3
+move 6 from 2 to 7
+move 6 from 7 to 8
+move 7 from 1 to 9
+move 4 from 1 to 6
+move 2 from 1 to 2
+move 4 from 6 to 7
+move 1 from 2 to 9
+move 1 from 2 to 3
+move 1 from 2 to 1
+move 6 from 8 to 4
+move 2 from 6 to 7
+move 13 from 5 to 9
+move 1 from 5 to 4
+move 3 from 4 to 7
+move 1 from 1 to 7
+move 14 from 9 to 2
+move 2 from 9 to 3
+move 3 from 8 to 5
+move 4 from 3 to 4
+move 8 from 4 to 1
+move 7 from 1 to 9
+move 5 from 6 to 9
+move 4 from 9 to 2
+move 1 from 1 to 9
+move 17 from 2 to 4
+move 1 from 6 to 3
+move 4 from 7 to 5
+move 5 from 7 to 5
+move 1 from 6 to 4
+move 1 from 8 to 3
+move 5 from 7 to 1
+move 2 from 7 to 6
+move 2 from 3 to 6
+move 1 from 2 to 9
+move 7 from 9 to 6
+move 2 from 3 to 7
+move 8 from 6 to 4
+move 3 from 9 to 2
+move 1 from 6 to 4
+move 26 from 4 to 8
+move 2 from 7 to 8
+move 5 from 5 to 9
+move 2 from 6 to 7
+move 4 from 9 to 1
+move 2 from 7 to 5
+move 14 from 8 to 6
+move 3 from 2 to 8
+move 3 from 6 to 8
+move 3 from 6 to 1
+move 10 from 8 to 4
+move 5 from 9 to 4
+move 3 from 8 to 5
+move 1 from 8 to 2
+move 12 from 4 to 8
+move 1 from 9 to 3
+move 6 from 6 to 4
+move 6 from 8 to 2
+move 1 from 3 to 8
+move 1 from 8 to 4
+move 10 from 1 to 9
+move 2 from 1 to 3
+move 7 from 4 to 9
+move 1 from 2 to 1
+move 11 from 8 to 9
+move 1 from 3 to 9
+move 2 from 2 to 7
+move 1 from 3 to 6
+move 2 from 7 to 9
+move 2 from 4 to 6
+move 4 from 6 to 4
+move 2 from 2 to 8
+move 2 from 8 to 4
+move 1 from 1 to 7
+move 2 from 2 to 8
+move 9 from 5 to 2
+move 3 from 5 to 9
+move 1 from 8 to 3
+move 30 from 9 to 7
+move 1 from 6 to 2
+move 7 from 4 to 8
+move 13 from 7 to 2
+move 8 from 7 to 4
+move 2 from 4 to 8
+move 8 from 8 to 1
+move 1 from 8 to 3
+move 2 from 8 to 9
+move 1 from 3 to 7
+move 5 from 7 to 6
+move 1 from 3 to 1
+move 7 from 4 to 8
+move 20 from 2 to 6
+move 2 from 2 to 7
+move 1 from 9 to 5
+move 4 from 7 to 6
+move 3 from 7 to 8
+move 1 from 7 to 2
+move 7 from 8 to 6
+move 3 from 6 to 7
+move 4 from 9 to 1
+move 1 from 2 to 6
+move 1 from 9 to 7
+move 1 from 2 to 8
+move 1 from 7 to 6
+move 3 from 6 to 3
+move 4 from 8 to 1
+move 8 from 6 to 4
+move 3 from 7 to 2
+move 1 from 3 to 2
+move 1 from 4 to 5
+move 2 from 3 to 5
+move 1 from 4 to 6
+move 4 from 1 to 5
+move 4 from 2 to 9
+move 2 from 1 to 6
+move 4 from 9 to 2
+move 3 from 2 to 8
+move 2 from 8 to 4
+move 13 from 6 to 1
+move 4 from 5 to 2
+move 14 from 6 to 3
+move 1 from 2 to 7
+move 2 from 2 to 4
+move 1 from 8 to 6
+move 1 from 6 to 3
+move 1 from 7 to 4
+move 1 from 2 to 3
+move 1 from 2 to 6
+move 11 from 4 to 6
+move 2 from 5 to 4
+move 1 from 5 to 6
+move 12 from 3 to 6
+move 1 from 3 to 7
+move 1 from 5 to 7
+move 3 from 3 to 6
+move 2 from 7 to 5
+move 2 from 5 to 2
+move 8 from 6 to 7
+move 24 from 1 to 3
+move 1 from 4 to 6
+move 10 from 3 to 1
+move 6 from 1 to 8
+move 1 from 6 to 3
+move 1 from 4 to 2
+move 1 from 3 to 1
+move 2 from 2 to 1
+move 1 from 7 to 6
+move 2 from 7 to 5
+move 4 from 3 to 7
+move 1 from 2 to 3
+move 6 from 1 to 6
+move 3 from 7 to 5
+move 4 from 7 to 8
+move 1 from 1 to 2
+move 1 from 2 to 7
+move 8 from 3 to 4
+move 3 from 4 to 7
+move 6 from 8 to 6
+move 2 from 3 to 2
+move 1 from 3 to 9
+move 5 from 5 to 1
+move 2 from 8 to 2
+move 1 from 9 to 2
+move 4 from 1 to 3
+move 3 from 2 to 9
+move 1 from 1 to 2
+move 2 from 9 to 7
+move 2 from 2 to 9
+move 8 from 7 to 5
+move 33 from 6 to 5
+move 20 from 5 to 9
+move 21 from 5 to 7
+move 17 from 7 to 6
+move 10 from 6 to 9
+move 5 from 4 to 7
+move 2 from 3 to 9
+move 1 from 2 to 3
+move 2 from 7 to 3
+move 3 from 9 to 5
+move 23 from 9 to 7
+move 8 from 9 to 6
+move 1 from 9 to 1
+move 1 from 5 to 3
+move 1 from 8 to 9
+move 5 from 6 to 8
+move 1 from 9 to 6
+move 18 from 7 to 2
+move 6 from 7 to 4
+move 6 from 4 to 8
+move 5 from 7 to 4
+move 6 from 6 to 3
+move 1 from 4 to 2
+move 10 from 2 to 1
+move 1 from 2 to 4
+move 7 from 1 to 6
+move 1 from 7 to 1
+move 11 from 6 to 2
+move 1 from 6 to 8
+move 12 from 3 to 1
+move 8 from 1 to 8
+move 2 from 5 to 2
+move 12 from 8 to 6
+move 15 from 2 to 4
+move 7 from 4 to 5
+move 4 from 5 to 9
+move 4 from 9 to 4
+move 5 from 4 to 6
+move 2 from 5 to 2
+move 1 from 2 to 5
+move 2 from 5 to 4
+move 2 from 1 to 3
+move 4 from 1 to 5
+move 2 from 8 to 4
+move 5 from 2 to 9
+move 17 from 6 to 8
+move 1 from 3 to 2
+move 2 from 5 to 4
+move 1 from 3 to 8
+move 1 from 1 to 6
+move 2 from 5 to 6
+move 3 from 9 to 5
+move 1 from 5 to 1
+move 3 from 1 to 8
+move 26 from 8 to 4
+move 1 from 5 to 3
+move 3 from 2 to 7
+move 1 from 5 to 7
+move 21 from 4 to 9
+move 19 from 4 to 5
+move 3 from 4 to 3
+move 2 from 7 to 5
+move 1 from 8 to 2
+move 1 from 6 to 2
+move 1 from 8 to 9
+move 1 from 6 to 7
+move 1 from 2 to 4
+move 1 from 4 to 7
+move 1 from 2 to 7
+move 1 from 7 to 1
+move 1 from 1 to 6
+move 1 from 3 to 5
+move 2 from 6 to 3
+move 13 from 5 to 8
+move 1 from 4 to 2
+move 3 from 5 to 4
+move 5 from 5 to 4
+move 5 from 8 to 9
+move 9 from 9 to 3
+move 2 from 7 to 1
+move 6 from 4 to 2
+move 8 from 9 to 4
+move 1 from 2 to 7
+move 12 from 9 to 8
+move 1 from 4 to 2
+move 3 from 7 to 3
+move 11 from 8 to 5
+move 5 from 8 to 6
+move 3 from 6 to 5
+move 2 from 4 to 1
+move 13 from 5 to 3
+move 1 from 1 to 7
+move 2 from 1 to 8
+move 3 from 4 to 9
+move 1 from 1 to 7
+move 1 from 2 to 4
+move 2 from 7 to 3
+move 1 from 5 to 3
+move 4 from 4 to 2
+move 1 from 4 to 9
+move 30 from 3 to 2
+move 1 from 9 to 7
+move 6 from 8 to 6
+move 1 from 7 to 6
+move 1 from 5 to 1
+move 1 from 3 to 5
+move 30 from 2 to 3
+move 1 from 1 to 9
+move 2 from 9 to 2
+move 9 from 6 to 9
+move 2 from 2 to 9
+move 1 from 5 to 1
+move 5 from 9 to 7
+move 8 from 2 to 5
+move 1 from 1 to 9
+move 3 from 9 to 1
+move 5 from 3 to 6
+move 8 from 5 to 9
+move 13 from 3 to 9
+move 3 from 1 to 7
+move 5 from 7 to 9
+move 17 from 9 to 6
+move 1 from 7 to 6
+move 6 from 3 to 9
+move 1 from 2 to 1
+move 2 from 7 to 1
+move 1 from 2 to 5
+move 21 from 9 to 2
+move 4 from 3 to 6
+move 6 from 6 to 5
+move 7 from 5 to 9
+move 2 from 3 to 8
+move 3 from 1 to 3
+move 4 from 6 to 5
+move 1 from 8 to 1
+move 1 from 8 to 2
+move 4 from 5 to 2
+move 4 from 9 to 1
+move 4 from 3 to 5
+move 2 from 1 to 7
+move 1 from 7 to 4
+move 3 from 9 to 5
+move 25 from 2 to 9
+move 18 from 9 to 1
+move 1 from 4 to 5
+move 1 from 3 to 8
+move 4 from 5 to 6
+move 2 from 9 to 3
+move 17 from 1 to 5
+move 1 from 2 to 7
+move 2 from 3 to 5
+move 3 from 1 to 8
+move 5 from 9 to 2
+move 4 from 8 to 9
+move 12 from 5 to 2
+move 1 from 1 to 8
+move 3 from 9 to 5
+move 1 from 8 to 2
+move 2 from 7 to 2
+move 1 from 9 to 5
+move 9 from 5 to 2
+move 6 from 6 to 2
+move 15 from 6 to 2
+move 5 from 5 to 9
+move 1 from 5 to 9
+move 3 from 9 to 2
+move 3 from 9 to 1
+move 1 from 1 to 9
+move 1 from 9 to 1
+move 19 from 2 to 8
+move 2 from 1 to 9
+move 33 from 2 to 6
+move 4 from 6 to 4
+move 1 from 2 to 6
+move 1 from 9 to 8
+move 3 from 4 to 8
+move 18 from 8 to 3
+move 1 from 4 to 9
+move 10 from 3 to 9
+move 1 from 1 to 4
+move 24 from 6 to 3
+move 1 from 4 to 3
+move 2 from 8 to 7
+move 8 from 9 to 3
+move 5 from 6 to 7
+move 35 from 3 to 2
+move 7 from 7 to 1
+move 3 from 1 to 3
+move 33 from 2 to 6
+move 6 from 3 to 7
+move 5 from 7 to 3
+move 1 from 1 to 4
+move 1 from 7 to 8
+move 1 from 4 to 8
+move 1 from 3 to 2
+move 30 from 6 to 5
+move 2 from 1 to 6
+move 5 from 8 to 1
+move 1 from 9 to 2
+move 2 from 6 to 4
+move 4 from 1 to 7
+move 21 from 5 to 8
diff --git a/day05/examples/test.txt b/day05/examples/test.txt
new file mode 100644
index 0000000..84933bb
--- /dev/null
+++ b/day05/examples/test.txt
@@ -0,0 +1,9 @@
+ [D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+
+move 1 from 2 to 1
+move 3 from 1 to 3
+move 2 from 2 to 1
+move 1 from 1 to 2
diff --git a/day06/app/Main.hs b/day06/app/Main.hs
new file mode 100644
index 0000000..68f1492
--- /dev/null
+++ b/day06/app/Main.hs
@@ -0,0 +1,154 @@
+{-
+--- Day 6: Tuning Trouble ---
+
+The preparations are finally complete; you and the Elves leave camp on foot and begin to make
+your way toward the star fruit grove.
+
+As you move through the dense undergrowth, one of the Elves gives you a handheld device. He
+says that it has many fancy features, but the most important one to set up right now is the
+communication system.
+
+However, because he's heard you have significant experience dealing with signal-based systems,
+he convinced the other Elves that it would be okay to give you their one malfunctioning device
+- surely you'll have no problem fixing it.
+
+As if inspired by comedic timing, the device emits a few colorful sparks.
+
+To be able to communicate with the Elves, the device needs to lock on to their signal. The
+signal is a series of seemingly-random characters that the device receives one at a time.
+
+To fix the communication system, you need to add a subroutine to the device that detects a
+start-of-packet marker in the datastream. In the protocol being used by the Elves, the start
+of a packet is indicated by a sequence of four characters that are all different.
+
+The device will send your subroutine a datastream buffer (your puzzle input); your subroutine
+needs to identify the first position where the four most recently received characters were all
+different. Specifically, it needs to report the number of characters from the beginning of the
+buffer to the end of the first such four-character marker.
+
+For example, suppose you receive the following datastream buffer:
+
+```
+mjqjpqmgbljsphdztnvjfqwrcgsmlb
+```
+
+After the first three characters (mjq) have been received, there haven't been enough characters
+received yet to find the marker. The first time a marker could occur is after the fourth
+character is received, making the most recent four characters mjqj. Because j is repeated, this
+isn't a marker.
+
+The first time a marker appears is after the seventh character arrives. Once it does, the last
+four characters received are jpqm, which are all different. In this case, your subroutine
+should report the value 7, because the first start-of-packet marker is complete after 7
+characters have been processed.
+
+Here are a few more examples:
+
+ bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 5
+ nppdvjthqldpwncqszvftbrmjlhg: first marker after character 6
+ nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 10
+ zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 11
+
+How many characters need to be processed before the first start-of-packet marker is detected?
+
+--- Part Two ---
+
+Your device's communication system is correctly detecting packets, but still isn't working. It
+looks like it also needs to look for messages.
+
+A start-of-message marker is just like a start-of-packet marker, except it consists of 14
+distinct characters rather than 4.
+
+Here are the first positions of start-of-message markers for all of the above examples:
+
+ mjqjpqmgbljsphdztnvjfqwrcgsmlb: first marker after character 19
+ bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 23
+ nppdvjthqldpwncqszvftbrmjlhg: first marker after character 23
+ nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 29
+ zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 26
+
+How many characters need to be processed before the first start-of-message marker is detected?
+-}
+{-# LANGUAGE DerivingStrategies #-}
+{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
+{-# HLINT ignore "Use ordNub" #-}
+{-# OPTIONS_GHC -Wno-unsafe #-}
+
+module Main (main) where
+
+import Data.ByteString.Lazy (ByteString)
+import Data.Discrimination (Grouping, nub)
+import Data.List (findIndex, length)
+import Options.Applicative (Parser, ParserInfo, argument, execParser, fullDesc, help, helper, info, metavar, str)
+import Relude hiding (ByteString, elem, empty, filter, fromList, length, null, optional, readFile, splitAt)
+import Text.Parsec (ParseError, parse, (<?>))
+import Text.Parsec.ByteString.Lazy (GenParser)
+import Text.Parsec.Char (anyChar, string)
+import Text.Parsec.Combinator (eof, many1)
+import Text.Parsec.Prim (parsecMap, try)
+
+type Opts :: Type
+newtype Opts = Opts {_filename :: Text} deriving stock (Show)
+
+parseInput :: FilePath -> ByteString -> Either ParseError String
+parseInput = parse $ many1 anyChar <* (eol <|> eof)
+ where
+ eol :: GenParser t st ()
+ eol =
+ parsecMap
+ (const ())
+ ( try (string "\n\r")
+ <|> try (string "\r\n")
+ <|> string "\n"
+ <|> string "\r"
+ <?> "end of line"
+ )
+
+window :: Int -> [a] -> [[a]]
+window n xs =
+ if n > length xs
+ then []
+ else take n xs : window n (drop 1 xs)
+
+allunique :: Grouping a => [a] -> Bool
+allunique xs = nub xs == xs
+
+run :: Int -> String -> Maybe Int
+run nchars = findIndex allunique . window nchars
+
+runPart1 :: String -> Int
+runPart1 xs = case run nchars xs of
+ Nothing -> error "Failure"
+ Just res -> nchars + res
+ where
+ nchars :: Int
+ nchars = 4
+
+runPart2 :: String -> Int
+runPart2 xs = case run nchars xs of
+ Nothing -> error "Failure"
+ Just res -> nchars + res
+ where
+ nchars :: Int
+ nchars = 14
+
+main :: IO ()
+main = do
+ fileName <- toString . _filename <$> execParser opts
+ rawInput <- readFileLBS fileName
+ case parseInput fileName rawInput of
+ Left e -> do
+ putTextLn "Error parsing input:"
+ print e
+ Right r -> do
+ print $ runPart1 r
+ print $ runPart2 r
+ where
+ opts :: ParserInfo Opts
+ opts = info (helper <*> options) fullDesc
+
+ options :: Parser Opts
+ options = Opts <$> filename
+
+ filename :: Parser Text
+ filename = argument str $ metavar "filename" <> help "Input file"
diff --git a/day06/day06.cabal b/day06/day06.cabal
new file mode 100644
index 0000000..a189f1f
--- /dev/null
+++ b/day06/day06.cabal
@@ -0,0 +1,35 @@
+cabal-version: 2.4
+name: day06
+version: 0.1.0.0
+synopsis:
+
+-- A URL where users can report bugs.
+-- bug-reports:
+license:
+author: Shivesh Mandalia
+maintainer: mail@shivesh.org
+
+executable day06
+ main-is: Main.hs
+
+ -- Modules included in this executable, other than Main.
+ -- other-modules:
+
+ -- LANGUAGE extensions used by modules in this package.
+ default-extensions:
+ NoImplicitPrelude
+ OverloadedStrings
+ StandaloneKindSignatures
+
+ build-depends:
+ , base ^>=4.16.4.0
+ , discrimination >=0.5
+ , optparse-applicative >=0.17.0.0
+ , parsec >=3.1.16.1
+ , relude ^>=1.1.0.0
+
+ hs-source-dirs: app
+ default-language: Haskell2010
+ ghc-options:
+ -Weverything -Wno-unused-packages -Wno-missing-safe-haskell-mode
+ -Wno-safe -Wno-missing-import-lists
diff --git a/day06/examples/input.txt b/day06/examples/input.txt
new file mode 100644
index 0000000..636557c
--- /dev/null
+++ b/day06/examples/input.txt
@@ -0,0 +1 @@
+gzbzwzjwwrfftfrrbvvcbcvcffpssvhhzfzbfzzrbrtrcttnthnhsnhsnnclcpctpprwwgppppchhvvctvtsvswwcdcrrdzdhzdzvddvfvfjjlldvvfllfhlfhlhghnhghrgrsggvbbhdhffzggmttjqtjjgljjwtjwjggldlzzrfrpppjsjggqrrdbbgwgtwwwtqwtqqvccjnnhrhqqsnssjbssmjjbzjjqnqnlnjncjjzzqddfqqqnqvnqncqqmsshqqccssvpvllbbfvfmmmgzgdggtjgjtjbttngtnnhhfrfddmtmtftcftthvttwzwrzrbrgrbrqbqccmmtvtqvtqqzmzwmzzzsvzvhhhqlhqlqplpggvmvwmmshhnshsjszzljlnlrnllgddqllpmllsgswwqnqlnlqqlmqqvrqvrqrppvrrqwqhqllgjgcggsllqgllghlghhbvhhcvvbddvcvwwwzdzzfjjvcczbbwccjvccmvmfvfgfmfttwrttpmtmsszccjggcssmqsmsgszzfpphghvgvvcddtltwlwnnrbbfdbbtssrvvmwwjfflmlblwlrlmlwwhrhnhqnnvdvllzblzzndzdlzzhpprbrprnrzrjjlnlnrrjddgrrwrttcstsgshszzvgvfvpfpqfpfbpbfbwbmmzvvnnqvvqppzspzpzplldqlqsqlldmlmgmcmwmsmfsfzfdzzbpzzbbcwbbtppphlhshchjjszztctpprqppszzchcqczczddscsrstsntstjsjqjjfggvccgbggqhghrhppdldnlndnpddllgplgppnlpnnmwwglghhftfrtrqtqsszrssfjjzhzfhfssflfslsmmgrrcdrdnrdnnqznndrrbtrrmhrhbhsbsgsnslsqlqnncpccplpldpldppshsdssqdsqdsqdsdsdfsddchczhczcszcscffzhfzffpbbgttdhthnhnjnwnnwrrmwmlljzlzlzdzrrcvcbbsfstfsfnfqftqffgjfjzfjfsjswswccsvcvlccshhjpjcccnfnqqmsqmmrwmwjwswgsgjsjttmjmjttpqtqwttgmgfmmnbnrnpnwppgspggwnwqnqpqmmbmmnwnllbwwdqqzsqqtgttnrtrllcwcchpchcbhbpbnpbpsptpvtvzvrzzslljddjzjjmqmmdpmddcdzzrdrqddtctppwzzwrzrvzrvrzzjtztqqsmmcncllhmlmpmhgsrtrzjhjbtfvhmzpssfbjwcdshthnmmqmfhlhwcbbllwzbwfgfvzjcqblchzqqqgcgmpnbnnblhbcpgmvsbvtcmhsghldlhqlghgtpdvjflmjsmppdsvrjlwvhmwsmfvvdnzpmtfqjqpjdctnnrlfjfvdtmvdmhsczlfsqwfrqtlqwnzdzrcdzmhvrgwnjjtqjrqljhgcffglvhnsdssqdpfrfhtjwlqzvfjmpjnqhsjvndtstqjsqgcmgqdjvfqnlmtjlvcblndprmffrgqdnnncnlfflclgqbjbmsdqsjrmzpwtbqqqqsqmgthhjfqwzvcbqwlvdbffhcvncpldmchnptbnlbhmzrrjhzvzdrvtlhsnfnfdnvhlrlrmdcpnmvdwswctcqldszlvftqtwldrhmfjmfvcgjcdjsbjqjwdtslblwhqfvgrfcpnhszqqsfwbwcmvfvccvztdmcjqfjvdvmbdtcjvtwqpwsqjtdvpvvvsdrrvngmjztgjtnpdbmtlrbrjlwsdnthgzgpssgbzzrqvgblqhrtfbflnphvhpzmdfrwqvjjvcpsmdrqwdbzlpnqpmglgqzfhctrzdpzdthqgjtvpwcrlsmqnjwgzlnqbthvfswhjtrrsrswhbmnddgzmznvppbnmtjpzpdpmpzpmsgfstzldgmrtgplwwsbztphtcvdfgsqzqwrmlqpnhvpcqpfjpbrthrtwgqlfnrqcrpvhssjmhfgpnzzvlrlcbnpmddhtdvvfrrvprqrwbhfgvvltgrhrpwsdgvrlgthbztcgcfggtcfzqtlcdhpmcvpgcszslhpfrttnrdrqpqlgdfwtccmbhfrnlbhhmrtrjmzstbqhmtphzcpcllzsnghfvlwvzzvlqrjmfsvhrnjnvldgnbqvpjsmmphhrmhqrtcncmjwbdlqtrvmhgjrjsrddcpqnjhfmczfgwzspnrjfwvfdpdlcfpvctfrlspdwwlnpbvbglzsmgfsmrshsqgcvlfrvjssrglbwvvvgpvtqshbtqmzbnglflhhldtfzqssptrbnnzdqwqtstpftdqgmmhfjdlfwtmcmtmcgcvtfhzvsbllgbchvlhrgnvvbsnrwqrlvdqlcwwlgbjrvrzgcvljqzvdngtbhpnppjrzpmbwztzvnvrbfccfgvnqvrcmpdblngcvlwjwzpbbwmnslsdjmbrwbvnjsgcmsfvzvnwbzrrlzvgdnzcqqgggvmcwczjqnrddnzhlndgzjbvtbtjqdnlvlflqnfvjdmfstpdfqsgjdslgtpgdnvvpmfwvlqbmbgdrqjhdfhlmsdtfwpscsvdzmswszjfwqtsjqpfnjjlnsspvlgzwwtvwgdzfjjljfwbvfbvpglcqcdbdpshwcqzswbwhftbfqblzpqfmqpvzdjsrcqtvjntnhmlhmzllffcjsdnwpfzdglvlrhrljbrhjhgdnfcqcrccwrbbhrvqwrzlwjrrwzsfcwsvbqsjgtgpzqwlczljrtdhtzcgsfgqssdbjjmttdtzhrqtbqjtqfwmcpdftrfjmznpscsqmtfcdpcdjwcqjvmhngcqnmtmwfttcvpwgcnhhgnnbgjdvztzhczvqljjqwcmwcbvmqqjsfnmhtbtsvsnsfwfzgdvlctrgdvbjqpgfrrlsnppmvhfbbclprlvcssnvtsgftmlpqrpjzrrphrzltbtgfwjqqvbgqjdpdgqvzppfzcbhdbbjttcdzclsphtlzfvnfqgpmqvpzrqgpdnbmsrqgsnfdwpvndzmsllgmnrlhnnzldwshtrrsrsmdncwrcjnmcjlwbbfpzcwzvldtgvbcvhnbhgjgwjcvslrfcwbqlrqldvpcgnbwbzzncncftrgbrwchfrrtnpqsjbcpzvplnbqdgtvnnrcwwfvbdzdrsfspvtbhflhsbqmlsjvfmpvjbfvcrdmgrfqsmqgfrntfqnlqbvmsqtpncjrstspbqvfmddmhwsssdcddshmwdlscttmdzljtpwhzhzhwsdnmgjstfmlnqqvzzdqpqsjdsllswmqcjtnthwqnhbscrjdstljqgncjvjvlpfrtscrzrqghrdvdnbtnpshpldcchljzrzqjlwwscnphvrwlvzttcdjdrddgmvqpvdmttdqhwpfmslzvnrwlrrdttbhctgpgzjrmdwjbcmsprwggvmdmmltldgpbfnppnrpwcnpgtblccdvbsnfvgzmjppftvndmdslfshjvndfvvzjjlzhgfmhcggttrcrbrlwrqgjpchvhnjwqnbsnmftwszhzftglrfdvvnbcbzsslgmdchtrrrqqzhllrfhwfwbbdgfpdfwssmzcfcnzmrhfdddtdhfqmctsglqbwhwpnbdzbsfbbvvthrrgjvztjjwgjcgjntrddmmdldtmvjnwjbcqwfwvfhsrpchznhlqpcttqjffbrpbftftdjzlrqchmzrfgjrqlndfwfrghtsfsblcvtjmjrbfrwdgsgzmmjpdlbwzfscfsfcdqwdwnjwjbvvbptmfrqltmnlpbtrqspwdfmhnncqgtrtmbzhfmwrbcqhmmpmvprvwrjplspcmmspldmbgpbtmqjtrfcpfhcnpjbnlhjpzflstjqfqvzcnfgvrmtplndchffzrtfrqdpdnzrspddwmpzlfchrzzfcfvmbvfnlfwtfbvnffdqhljbvwwdtmszgrjtzwqdbgvvfphcnsdgvlmslqngfmsbrztrnpjprghmjffscbnfqwrvjjjtfzrmjtzbwdsmzgmbtjzvddhngmzvflwftblbzfd
diff --git a/day06/examples/test0.txt b/day06/examples/test0.txt
new file mode 100644
index 0000000..7980a82
--- /dev/null
+++ b/day06/examples/test0.txt
@@ -0,0 +1 @@
+mjqjpqmgbljsphdztnvjfqwrcgsmlb
diff --git a/day06/examples/test1.txt b/day06/examples/test1.txt
new file mode 100644
index 0000000..19fe247
--- /dev/null
+++ b/day06/examples/test1.txt
@@ -0,0 +1 @@
+bvwbjplbgvbhsrlpgdmjqwftvncz
diff --git a/day06/examples/test2.txt b/day06/examples/test2.txt
new file mode 100644
index 0000000..0f12ee2
--- /dev/null
+++ b/day06/examples/test2.txt
@@ -0,0 +1 @@
+nppdvjthqldpwncqszvftbrmjlhg
diff --git a/day06/examples/test3.txt b/day06/examples/test3.txt
new file mode 100644
index 0000000..38510e7
--- /dev/null
+++ b/day06/examples/test3.txt
@@ -0,0 +1 @@
+nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg
diff --git a/day06/examples/test4.txt b/day06/examples/test4.txt
new file mode 100644
index 0000000..e1d0a43
--- /dev/null
+++ b/day06/examples/test4.txt
@@ -0,0 +1 @@
+zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw
diff --git a/day07/app/Main.hs b/day07/app/Main.hs
new file mode 100644
index 0000000..413fcca
--- /dev/null
+++ b/day07/app/Main.hs
@@ -0,0 +1,259 @@
+{-
+--- Day 7: No Space Left On Device ---
+You can hear birds chirping and raindrops hitting leaves as the expedition proceeds.
+Occasionally, you can even hear much louder sounds in the distance; how big do the
+animals get out here, anyway?
+The device the Elves gave you has problems with more than just its communication system. You
+try to run a system update:
+```
+\$ system-update --please --pretty-please-with-sugar-on-top
+Error: No space left on device
+```
+Perhaps you can delete some files to make space for the update?
+You browse around the filesystem to assess the situation and save the resulting terminal output
+(your puzzle input). For example:
+```
+\$ cd /
+\$ ls
+dir a
+14848514 b.txt
+8504156 c.dat
+dir d
+\$ cd a
+\$ ls
+dir e
+29116 f
+2557 g
+62596 h.lst
+\$ cd e
+\$ ls
+584 i
+\$ cd ..
+\$ cd ..
+\$ cd d
+\$ ls
+4060174 j
+8033020 d.log
+5626152 d.ext
+7214296 k
+```
+The filesystem consists of a tree of files (plain data) and directories (which can contain
+other directories or files). The outermost directory is called /. You can navigate around the
+filesystem, moving into or out of directories and listing the contents of the directory you're
+currently in.
+Within the terminal output, lines that begin with $ are commands you executed, very much like
+some modern computers:
+ cd means change directory. This changes which directory is the current directory, but the
+ specific result depends on the argument:
+ cd x moves in one level: it looks in the current directory for the directory named x
+ and makes it the current directory.
+ cd .. moves out one level: it finds the directory that contains the current directory,
+ then makes that directory the current directory.
+ cd / switches the current directory to the outermost directory, /.
+ ls means list. It prints out all of the files and directories immediately contained by the
+ current directory:
+ 123 abc means that the current directory contains a file named abc with size 123.
+ dir xyz means that the current directory contains a directory named xyz.
+Given the commands and output in the example above, you can determine that the filesystem looks
+visually like this:
+```
+- / (dir)
+ - a (dir)
+ - e (dir)
+ - i (file, size=584)
+ - f (file, size=29116)
+ - g (file, size=2557)
+ - h.lst (file, size=62596)
+ - b.txt (file, size=14848514)
+ - c.dat (file, size=8504156)
+ - d (dir)
+ - j (file, size=4060174)
+ - d.log (file, size=8033020)
+ - d.ext (file, size=5626152)
+ - k (file, size=7214296)
+```
+Here, there are four directories: / (the outermost directory), a and d (which are in /), and e
+(which is in a). These directories also contain files of various sizes.
+Since the disk is full, your first step should probably be to find directories that are good
+candidates for deletion. To do this, you need to determine the total size of each directory.
+The total size of a directory is the sum of the sizes of the files it contains, directly or
+indirectly. (Directories themselves do not count as having any intrinsic size.)
+The total sizes of the directories above can be found as follows:
+ The total size of directory e is 584 because it contains a single file i of size 584 and no
+ other directories.
+ The directory a has total size 94853 because it contains files f (size 29116), g (size
+ 2557), and h.lst (size 62596), plus file i indirectly (a contains e which contains i).
+ Directory d has total size 24933642.
+ As the outermost directory, / contains every file. Its total size is 48381165, the sum of
+ the size of every file.
+To begin, find all of the directories with a total size of at most 100000, then calculate the
+sum of their total sizes. In the example above, these directories are a and e; the sum of
+their total sizes is 95437 (94853 + 584). (As in this example, this process can count files
+more than once!)
+Find all of the directories with a total size of at most 100000. What is the sum of the total
+sizes of those directories?
+
+--- Part Two ---
+
+Now, you're ready to choose a directory to delete.
+
+The total disk space available to the filesystem is 70000000. To run the update, you need
+unused space of at least 30000000. You need to find a directory you can delete that will free
+up enough space to run the update.
+
+In the example above, the total size of the outermost directory (and thus the total amount of
+used space) is 48381165; this means that the size of the unused space must currently be
+21618835, which isn't quite the 30000000 required by the update. Therefore, the update still
+requires a directory with total size of at least 8381165 to be deleted before it can run.
+
+To achieve this, you have the following options:
+
+ Delete directory e, which would increase unused space by 584.
+ Delete directory a, which would increase unused space by 94853.
+ Delete directory d, which would increase unused space by 24933642.
+ Delete directory /, which would increase unused space by 48381165.
+
+Directories e and a are both too small; deleting them would not free up enough space. However,
+directories d and / are both big enough! Between these, choose the smallest: d, increasing
+unused space by 24933642.
+
+Find the smallest directory that, if deleted, would free up enough space on the filesystem to
+run the update. What is the total size of that directory?
+-}
+{-# LANGUAGE DerivingStrategies #-}
+
+module Main (main) where
+
+import Data.ByteString.Lazy (ByteString)
+import Data.Char (digitToInt)
+import Data.Foldable
+import Data.List (filter)
+import Options.Applicative (Parser, ParserInfo, argument, execParser, fullDesc, help, helper, info, metavar, str)
+import Relude hiding (ByteString, elem, empty, filter, fromList, length, null, optional, readFile, splitAt, sum)
+import Text.Parsec (ParseError, parse, (<?>))
+import Text.Parsec.ByteString.Lazy (GenParser)
+import Text.Parsec.Char (anyChar, char, digit, string)
+import Text.Parsec.Combinator (eof, many1, manyTill)
+import Text.Parsec.Prim (parsecMap, try)
+
+type Opts :: Type
+newtype Opts = Opts {_filename :: Text} deriving stock (Show)
+
+type FileData :: Type
+data FileData = FileData {_name :: Text, _size :: Int} deriving stock (Show)
+
+type ParseDirOrFile :: Type
+data ParseDirOrFile = ParseDir | ParseFile FileData
+
+type Queries :: Type
+data Queries = ChangeDir Text | List [FileData] deriving stock (Show)
+
+type SystemEntry :: Type -> Type
+data SystemEntry a = File a | Directory Text [SystemEntry a] deriving stock (Show)
+
+root :: SystemEntry FileData
+root = Directory "/" []
+
+foldrEntry :: Monoid b => (a -> b -> b) -> b -> SystemEntry a -> b
+foldrEntry f b (File fd) = f fd b
+foldrEntry f b (Directory _ xs) = mconcat $ fmap (foldrEntry f b) xs
+
+instance Foldable SystemEntry where
+ foldMap fam = foldrEntry (mappend . fam) mempty
+
+parseInput :: FilePath -> ByteString -> Either ParseError [Queries]
+parseInput = parse $ queries <* (eol <|> eof)
+ where
+ queries :: GenParser t st [Queries]
+ queries = many1 (cd <|> ls)
+
+ cd :: GenParser t st Queries
+ cd = ChangeDir <$> (try (string "$ cd ") *> (toText <$> manyTill anyChar (eol <|> eof)))
+
+ ls :: GenParser t st Queries
+ ls = List . filterDir <$> ((try (string "$ ls") *> (eol <|> eof)) *> many1 (dir <|> file))
+
+ dir :: GenParser t st ParseDirOrFile
+ dir = ParseDir <$ try (string "dir ") <* manyTill anyChar (eol <|> eof)
+
+ file :: GenParser t st ParseDirOrFile
+ file = ParseFile <$> (flip FileData <$> (int <* char ' ') <*> (toText <$> manyTill anyChar (eol <|> eof)))
+
+ filterDir :: [ParseDirOrFile] -> [FileData]
+ filterDir [] = []
+ filterDir (ParseDir : xs) = filterDir xs
+ filterDir ((ParseFile fd) : xs) = fd : filterDir xs
+
+ int :: GenParser t st Int
+ int = foldl' (\a i -> a * 10 + digitToInt i) 0 <$> many1 digit
+
+ eol :: GenParser t st ()
+ eol =
+ parsecMap
+ (const ())
+ ( try (string "\n\r")
+ <|> try (string "\r\n")
+ <|> string "\n"
+ <|> string "\r"
+ <?> "end of line"
+ )
+
+run :: SystemEntry FileData -> [Queries] -> (SystemEntry FileData, [Queries])
+run se [] = (se, [])
+run (Directory n ses) (ChangeDir ".." : qs) = (Directory n ses, qs)
+run (Directory n ses) (ChangeDir d : qs) = run (Directory n (ses' : ses)) qs'
+ where
+ ses' :: SystemEntry FileData
+ (ses', qs') = run (Directory d []) qs
+run (Directory n ses) (List fd : qs) = run (Directory n (fmap File fd ++ ses)) qs
+run _ _ = error "invalid operation"
+
+getSize :: SystemEntry FileData -> Int
+getSize = getSum . foldr ((<>) . Sum . _size) (Sum 0)
+
+getDirSizes :: SystemEntry FileData -> [Int]
+getDirSizes (File _) = []
+getDirSizes (Directory n ses) =
+ getSize (Directory n ses) : foldl (\a d -> a ++ getDirSizes d) [] ses
+
+runPart1 :: [Queries] -> Int
+runPart1 = sum . filter (<= minSize) . getDirSizes . fst . run root . drop 1
+ where
+ minSize :: Int
+ minSize = 100000
+
+runPart2 :: [Queries] -> Int
+runPart2 qs = minimum $ filter (>= requiredSpace - unusedSpace) $ getDirSizes systemEntry
+ where
+ systemEntry :: SystemEntry FileData
+ systemEntry = fst $ run root $ drop 1 qs
+
+ unusedSpace :: Int
+ unusedSpace = totalSpace - getSize systemEntry
+
+ requiredSpace :: Int
+ requiredSpace = 30000000
+
+ totalSpace :: Int
+ totalSpace = 70000000
+
+main :: IO ()
+main = do
+ fileName <- toString . _filename <$> execParser opts
+ rawInput <- readFileLBS fileName
+ case parseInput fileName rawInput of
+ Left e -> do
+ putTextLn "Error parsing input:"
+ print e
+ Right r -> do
+ print $ runPart1 r
+ print $ runPart2 r
+ where
+ opts :: ParserInfo Opts
+ opts = info (helper <*> options) fullDesc
+
+ options :: Parser Opts
+ options = Opts <$> filename
+
+ filename :: Parser Text
+ filename = argument str $ metavar "filename" <> help "Input file"
diff --git a/day07/day07.cabal b/day07/day07.cabal
new file mode 100644
index 0000000..1053ca2
--- /dev/null
+++ b/day07/day07.cabal
@@ -0,0 +1,35 @@
+cabal-version: 2.4
+name: day07
+version: 0.1.0.0
+synopsis:
+
+-- A URL where users can report bugs.
+-- bug-reports:
+license:
+author: Shivesh Mandalia
+maintainer: mail@shivesh.org
+
+executable day07
+ main-is: Main.hs
+
+ -- Modules included in this executable, other than Main.
+ -- other-modules:
+
+ -- LANGUAGE extensions used by modules in this package.
+ default-extensions:
+ NoImplicitPrelude
+ OverloadedStrings
+ StandaloneKindSignatures
+
+ build-depends:
+ , base ^>=4.16.4.0
+ , discrimination >=0.5
+ , optparse-applicative >=0.17.0.0
+ , parsec >=3.1.16.1
+ , relude ^>=1.1.0.0
+
+ hs-source-dirs: app
+ default-language: Haskell2010
+ ghc-options:
+ -Weverything -Wno-unused-packages -Wno-missing-safe-haskell-mode
+ -Wno-safe -Wno-missing-import-lists
diff --git a/day07/examples/input.txt b/day07/examples/input.txt
new file mode 100644
index 0000000..1c87c00
--- /dev/null
+++ b/day07/examples/input.txt
@@ -0,0 +1,979 @@
+$ cd /
+$ ls
+dir plws
+dir pwlbgbz
+dir pwtpltr
+dir szn
+$ cd plws
+$ ls
+dir ffpzc
+dir frcmjzts
+92461 nbvnzg
+dir phqcg
+21621 vqgsglwq
+$ cd ffpzc
+$ ls
+48459 dzdfc.vqq
+143107 jql.jzl
+208330 mmnvqn.hqb
+290122 svjvhflz
+218008 wjlmgq
+$ cd ..
+$ cd frcmjzts
+$ ls
+dir bsltmjz
+dir jfzgrbm
+$ cd bsltmjz
+$ ls
+34237 dzdfc.vqq
+58741 mdgdhqgw
+$ cd ..
+$ cd jfzgrbm
+$ ls
+132811 fcmpng
+103661 lgt.swt
+173031 vqgsglwq
+29134 wprjfg.zbr
+$ cd ..
+$ cd ..
+$ cd phqcg
+$ ls
+955 jgfs.zjw
+$ cd ..
+$ cd ..
+$ cd pwlbgbz
+$ ls
+dir gbg
+dir mjzhcwrd
+dir njcscpj
+dir sphbzn
+dir tbgjpphc
+55938 tvrfpczc.djm
+4840 twd
+$ cd gbg
+$ ls
+287003 fcsjl.bzm
+dir wgq
+$ cd wgq
+$ ls
+22963 fcsjl.fcm
+$ cd ..
+$ cd ..
+$ cd mjzhcwrd
+$ ls
+228632 clfnpmbq.zmb
+28276 dzdfc.vqq
+2982 tdbg.wgn
+$ cd ..
+$ cd njcscpj
+$ ls
+dir dqzgqgv
+275186 ffpzc
+192491 gjnflc.plq
+$ cd dqzgqgv
+$ ls
+70309 dzdfc.vqq
+56139 fcsjl
+142095 sgwz.cdz
+dir snjntth
+dir sphbzn
+284618 wjlmgq
+$ cd snjntth
+$ ls
+51918 ffpzc
+dir vrfgfds
+$ cd vrfgfds
+$ ls
+155233 jlscz
+$ cd ..
+$ cd ..
+$ cd sphbzn
+$ ls
+dir qbzwrrw
+dir qwpzn
+$ cd qbzwrrw
+$ ls
+278531 fcsjl.tqj
+211591 snjntth.gpd
+$ cd ..
+$ cd qwpzn
+$ ls
+174183 vqgsglwq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd sphbzn
+$ ls
+185471 bsltmjz.fqz
+dir bsvh
+dir fvzcs
+dir ndw
+dir nlml
+dir pcbt
+286260 zhcmrpvt
+$ cd bsvh
+$ ls
+130814 wjlmgq
+$ cd ..
+$ cd fvzcs
+$ ls
+dir cgmv
+dir ggzwljr
+298241 qvzghdpw.lms
+dir snjntth
+dir sphbzn
+$ cd cgmv
+$ ls
+46843 dzdfc.vqq
+dir lmqcbbm
+dir rstcqsmd
+215261 snjntth
+$ cd lmqcbbm
+$ ls
+229898 bdmbvgp
+25529 ffpzc.stm
+16871 lnpjzvg.qlj
+$ cd ..
+$ cd rstcqsmd
+$ ls
+289038 zrbbbwng.smf
+$ cd ..
+$ cd ..
+$ cd ggzwljr
+$ ls
+198200 bcthn
+$ cd ..
+$ cd snjntth
+$ ls
+191672 fwp.phf
+68229 hzs.zpg
+dir pggcwb
+222426 qbv.bwj
+dir snjntth
+155354 vmqcm
+$ cd pggcwb
+$ ls
+154272 fqztwvnv.lvv
+dir pdjg
+62393 vqgsglwq
+dir wjhrtg
+$ cd pdjg
+$ ls
+260644 gvhlrcf
+209906 wpls.pbd
+$ cd ..
+$ cd wjhrtg
+$ ls
+148640 dljf.zrq
+172168 dzdfc.vqq
+196203 hjdphcfm
+247620 sgwz.cdz
+$ cd ..
+$ cd ..
+$ cd snjntth
+$ ls
+37467 ndlshlmj.cjq
+257404 snjntth.nsf
+$ cd ..
+$ cd ..
+$ cd sphbzn
+$ ls
+64082 bfdv.lwv
+dir bsltmjz
+58942 dzdfc.vqq
+dir snjntth
+$ cd bsltmjz
+$ ls
+dir bsqqdr
+266007 fcsjl.gfm
+dir ffpzc
+dir frsmrd
+72122 nthnhzwf
+286705 wjlmgq
+$ cd bsqqdr
+$ ls
+117496 wcqt
+$ cd ..
+$ cd ffpzc
+$ ls
+280224 mmnvqn.hqb
+105346 vrr
+$ cd ..
+$ cd frsmrd
+$ ls
+111509 sphbzn.shz
+$ cd ..
+$ cd ..
+$ cd snjntth
+$ ls
+177491 mplj
+9029 pvbz.jwn
+92891 snjntth.zrv
+203356 vnnnw.gql
+134728 vqgsglwq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ndw
+$ ls
+241303 bht.rpj
+173068 vqgsglwq
+$ cd ..
+$ cd nlml
+$ ls
+228982 hzglfpvq.ftt
+114981 sgwz.cdz
+$ cd ..
+$ cd pcbt
+$ ls
+dir bsltmjz
+dir ffpzc
+dir fjsjwfg
+dir fwm
+dir jvwt
+227943 tmr.jdc
+dir vwpqzdwh
+31258 wjlmgq
+$ cd bsltmjz
+$ ls
+177750 bsltmjz.spj
+dir ffpzc
+dir flrpwfs
+138824 mtmdtcpv.cfj
+165770 wzqwczj.qwn
+$ cd ffpzc
+$ ls
+179645 snjntth.dss
+$ cd ..
+$ cd flrpwfs
+$ ls
+60566 wvjq.gmm
+$ cd ..
+$ cd ..
+$ cd ffpzc
+$ ls
+97847 qzhhtmd.bhw
+1197 vqgsglwq
+$ cd ..
+$ cd fjsjwfg
+$ ls
+152232 dnsdd.jgz
+181301 gsb.wsh
+dir jqpb
+dir jscbg
+dir snjntth
+227677 snjntth.vvg
+dir sphbzn
+75358 vqgsglwq
+2589 wjlmgq
+$ cd jqpb
+$ ls
+253403 mmnvqn.hqb
+108325 rvq.mrc
+$ cd ..
+$ cd jscbg
+$ ls
+dir dtm
+dir gsdnz
+208269 prh
+25977 qdzljgh
+169262 vmnq.mth
+$ cd dtm
+$ ls
+80072 gzqnb
+$ cd ..
+$ cd gsdnz
+$ ls
+dir dsqzjs
+297895 sgwz.cdz
+129983 vqgsglwq
+$ cd dsqzjs
+$ ls
+2621 jqrlsf.gzs
+164844 snjntth
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd snjntth
+$ ls
+118553 cbhql
+dir ffpzc
+dir snjntth
+$ cd ffpzc
+$ ls
+dir lmn
+12104 tvlwn.vhh
+$ cd lmn
+$ ls
+46401 bsltmjz
+96888 shrnqhvq
+$ cd ..
+$ cd ..
+$ cd snjntth
+$ ls
+dir snjntth
+dir vlnfhbq
+dir wpwl
+$ cd snjntth
+$ ls
+dir ctj
+$ cd ctj
+$ ls
+82485 fcsjl.lfl
+$ cd ..
+$ cd ..
+$ cd vlnfhbq
+$ ls
+250106 qvf
+$ cd ..
+$ cd wpwl
+$ ls
+153950 cmsd.rlg
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd sphbzn
+$ ls
+dir glgq
+$ cd glgq
+$ ls
+285182 wjlmgq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd fwm
+$ ls
+251865 ffpzc.qgb
+279522 zvvpfqtp
+$ cd ..
+$ cd jvwt
+$ ls
+48990 bsltmjz.nzp
+219604 ffpzc
+69573 mvmdfzr.lwb
+$ cd ..
+$ cd vwpqzdwh
+$ ls
+267581 pvcch
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd tbgjpphc
+$ ls
+255571 dstpcgr.tfq
+dir fdbwbrpp
+dir gjzwh
+dir hjvrtjt
+dir rhzczj
+292888 sgwz.cdz
+dir wlzhr
+149395 wnfzrqgz.dtn
+$ cd fdbwbrpp
+$ ls
+dir ffpzc
+dir qbrth
+51164 qprp
+dir slpt
+117026 sphbzn
+295685 vqgsglwq
+dir znmj
+$ cd ffpzc
+$ ls
+dir jhnzrdvb
+$ cd jhnzrdvb
+$ ls
+217775 ffpzc.sgw
+$ cd ..
+$ cd ..
+$ cd qbrth
+$ ls
+183969 lpbwgfjv.vcg
+47333 wjlmgq
+$ cd ..
+$ cd slpt
+$ ls
+32343 tqhtj.jwz
+$ cd ..
+$ cd znmj
+$ ls
+55058 mmnvqn.hqb
+$ cd ..
+$ cd ..
+$ cd gjzwh
+$ ls
+dir dvcbcd
+202530 dzdfc.vqq
+dir fsgz
+dir hfrrqq
+54897 jlzn.qsn
+16097 ldzqsbb.jzl
+225078 pswccrd
+dir rqqmldw
+292464 rzrdhbp.vld
+dir ssqbqqp
+dir zsztqrc
+$ cd dvcbcd
+$ ls
+187837 dzdfc.vqq
+dir jlwtvf
+dir jnjvshs
+164053 nrf.fqd
+5665 tlp.jmt
+13801 wjlmgq
+$ cd jlwtvf
+$ ls
+219985 sphbzn.dvj
+$ cd ..
+$ cd jnjvshs
+$ ls
+dir bsltmjz
+dir nrpm
+$ cd bsltmjz
+$ ls
+152972 qgdqj
+$ cd ..
+$ cd nrpm
+$ ls
+18509 wjlmgq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd fsgz
+$ ls
+224576 mmnvqn.hqb
+$ cd ..
+$ cd hfrrqq
+$ ls
+dir bwgsnfvb
+dir fcsjl
+294608 ffpzc.gvm
+136880 qjcgtw
+dir sphbzn
+$ cd bwgsnfvb
+$ ls
+29735 dzdfc.vqq
+dir wstmzfml
+$ cd wstmzfml
+$ ls
+158447 bnvhbvvc.nrt
+59889 jclclgd
+$ cd ..
+$ cd ..
+$ cd fcsjl
+$ ls
+138297 ffpzc.szw
+$ cd ..
+$ cd sphbzn
+$ ls
+dir wqdths
+$ cd wqdths
+$ ls
+8326 cgvtw.jpz
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd rqqmldw
+$ ls
+226757 dzdfc.vqq
+115055 mwb.btc
+dir qpts
+298524 sgwz.cdz
+$ cd qpts
+$ ls
+60860 bsltmjz.frp
+dir fcsjl
+94904 sgwz.cdz
+dir wnmqqspz
+$ cd fcsjl
+$ ls
+25082 mmnvqn.hqb
+$ cd ..
+$ cd wnmqqspz
+$ ls
+165529 sgwz.cdz
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ssqbqqp
+$ ls
+192477 pvrgm
+$ cd ..
+$ cd zsztqrc
+$ ls
+254053 lht.htn
+$ cd ..
+$ cd ..
+$ cd hjvrtjt
+$ ls
+189942 fwps
+$ cd ..
+$ cd rhzczj
+$ ls
+36502 bmtfr
+dir ffjz
+35148 nctfhmzm.vsz
+dir qdgjzcz
+208196 rwql
+79863 sgwz.cdz
+dir snjntth
+$ cd ffjz
+$ ls
+dir grsvhwm
+$ cd grsvhwm
+$ ls
+50231 fwj.rdv
+dir snjntth
+$ cd snjntth
+$ ls
+dir dtbgb
+$ cd dtbgb
+$ ls
+150245 vdflm.lmq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd qdgjzcz
+$ ls
+222389 dzdfc.vqq
+$ cd ..
+$ cd snjntth
+$ ls
+56794 mmnvqn.hqb
+$ cd ..
+$ cd ..
+$ cd wlzhr
+$ ls
+116628 bsltmjz
+60122 jqpbsgnr.fgb
+252605 lfss
+300065 qwjdl.vhr
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd pwtpltr
+$ ls
+dir dplsvrhl
+140951 gwtfzqvd.znb
+dir jbvdb
+dir jst
+dir qhjv
+dir snjntth
+$ cd dplsvrhl
+$ ls
+272101 fcsjl
+dir ffpzc
+58852 mmnvqn.hqb
+dir mnhntjz
+91899 sgwz.cdz
+228077 snjntth.btv
+$ cd ffpzc
+$ ls
+5499 bsltmjz
+dir qmfwpjhl
+dir rsrb
+dir wgt
+$ cd qmfwpjhl
+$ ls
+300362 dzdfc.vqq
+$ cd ..
+$ cd rsrb
+$ ls
+252983 dzdfc.vqq
+107744 ltssrgqb.zvj
+214895 rhglgcwr.wpw
+249727 sgwz.cdz
+$ cd ..
+$ cd wgt
+$ ls
+141984 dzdfc.vqq
+194686 mmnvqn.hqb
+258023 pgr
+$ cd ..
+$ cd ..
+$ cd mnhntjz
+$ ls
+dir bdvght
+dir jprwchh
+dir snjntth
+$ cd bdvght
+$ ls
+243166 vpsvjdq.wsn
+$ cd ..
+$ cd jprwchh
+$ ls
+178943 bmpc.bjb
+$ cd ..
+$ cd snjntth
+$ ls
+dir nlbm
+dir zjmjntff
+$ cd nlbm
+$ ls
+33050 fcsjl.rcc
+dir sphbzn
+17446 wjlmgq
+$ cd sphbzn
+$ ls
+214563 prrfhff.pbp
+$ cd ..
+$ cd ..
+$ cd zjmjntff
+$ ls
+82134 sgwz.cdz
+52203 vrtlgdq.crp
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jbvdb
+$ ls
+dir wmtjh
+$ cd wmtjh
+$ ls
+dir ggvwn
+$ cd ggvwn
+$ ls
+192285 spqvmf.sdh
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jst
+$ ls
+dir bsltmjz
+212740 dzdfc.vqq
+dir gncztvtb
+dir jsqjcqnt
+286257 jvs
+36654 sdcsm.mbg
+192040 sgwz.cdz
+dir tbqphzb
+dir vdcqgts
+285843 wjlmgq
+$ cd bsltmjz
+$ ls
+215705 snjntth.gpv
+213665 wjlmgq
+$ cd ..
+$ cd gncztvtb
+$ ls
+229298 vqgsglwq
+$ cd ..
+$ cd jsqjcqnt
+$ ls
+dir bsltmjz
+dir fcsjl
+dir ffpzc
+dir sphbzn
+70864 vqgsglwq
+$ cd bsltmjz
+$ ls
+14981 pqzffzjc
+$ cd ..
+$ cd fcsjl
+$ ls
+140328 jwhczwbc
+$ cd ..
+$ cd ffpzc
+$ ls
+213650 mmnvqn.hqb
+$ cd ..
+$ cd sphbzn
+$ ls
+dir psmtphhq
+dir sphbzn
+$ cd psmtphhq
+$ ls
+dir ffpzc
+123131 tzgwd
+$ cd ffpzc
+$ ls
+49737 cfngvmd
+dir gcnrp
+172799 gmd.cwl
+dir llnztjf
+dir nbqs
+79661 rrqz
+$ cd gcnrp
+$ ls
+283 vqnrgl.vwp
+$ cd ..
+$ cd llnztjf
+$ ls
+63263 tjhm.bwh
+$ cd ..
+$ cd nbqs
+$ ls
+dir vssmq
+$ cd vssmq
+$ ls
+88980 dzdfc.vqq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd sphbzn
+$ ls
+20140 fcsjl.zrs
+260579 snjntth
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd tbqphzb
+$ ls
+93470 sgwz.cdz
+$ cd ..
+$ cd vdcqgts
+$ ls
+223564 dzdfc.vqq
+dir ffpzc
+dir gwhfgwf
+dir nbjtqnng
+dir snjntth
+$ cd ffpzc
+$ ls
+42813 qwwmw.nmt
+$ cd ..
+$ cd gwhfgwf
+$ ls
+59918 jvfv.mpm
+dir mjl
+211039 pcwl
+$ cd mjl
+$ ls
+13004 pgjb.tpq
+195995 tms.fjz
+$ cd ..
+$ cd ..
+$ cd nbjtqnng
+$ ls
+107058 dzdfc.vqq
+dir ldrsd
+111631 vqgsglwq
+104599 wbzmdljw.tjq
+155747 wjlmgq
+$ cd ldrsd
+$ ls
+107439 jvjm
+$ cd ..
+$ cd ..
+$ cd snjntth
+$ ls
+242680 fgrt.gng
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd qhjv
+$ ls
+dir bmnm
+68453 hjjpdgn.hwl
+dir sjlbj
+dir vqnrj
+$ cd bmnm
+$ ls
+1238 vqgsglwq
+$ cd ..
+$ cd sjlbj
+$ ls
+44239 wzzbtmrz.gml
+$ cd ..
+$ cd vqnrj
+$ ls
+3286 bsltmjz.qlc
+$ cd ..
+$ cd ..
+$ cd snjntth
+$ ls
+130833 blm.wmt
+dir snjntth
+dir tcnmbcgg
+218869 wjlmgq
+$ cd snjntth
+$ ls
+dir snmrdfbt
+$ cd snmrdfbt
+$ ls
+281025 bzrsds.lfg
+$ cd ..
+$ cd ..
+$ cd tcnmbcgg
+$ ls
+194998 fcsjl
+dir qdrmpqgn
+dir rzqd
+dir tcsds
+$ cd qdrmpqgn
+$ ls
+165713 qmzgt.tnc
+$ cd ..
+$ cd rzqd
+$ ls
+dir cwhnmlv
+57819 fcsjl
+246864 pjnzdvd.gjm
+$ cd cwhnmlv
+$ ls
+287539 mmnvqn.hqb
+215636 pbnjt.zbn
+124638 sqd
+$ cd ..
+$ cd ..
+$ cd tcsds
+$ ls
+78812 gfmgb.wqj
+218987 hnhfvz.dln
+209640 mzzhqlq.zqp
+102492 nml.ppg
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd szn
+$ ls
+dir fcsjl
+dir snjntth
+dir zjbp
+$ cd fcsjl
+$ ls
+158019 jsv.pmz
+$ cd ..
+$ cd snjntth
+$ ls
+229510 dfvpvp
+191061 fgplbptq.jlt
+dir lfb
+234911 lfsrwr.wcb
+dir lrfcgzl
+48031 stbbw
+219691 vqgsglwq
+dir zshh
+$ cd lfb
+$ ls
+dir btj
+99591 dhrjbvvg.gwm
+137224 dzdfc.vqq
+201972 jtzmqsvj.wnd
+9704 mmnvqn.hqb
+dir pwg
+200308 snjntth.css
+dir wcmhcfm
+dir zwhvmln
+$ cd btj
+$ ls
+dir rnbzdfgn
+51799 wdhsm
+dir wvf
+$ cd rnbzdfgn
+$ ls
+117095 bsltmjz.tlv
+$ cd ..
+$ cd wvf
+$ ls
+dir ffpzc
+dir ncbmgpsc
+dir wtwrmjnt
+$ cd ffpzc
+$ ls
+249919 lsth.fmf
+$ cd ..
+$ cd ncbmgpsc
+$ ls
+147899 dzdfc.vqq
+$ cd ..
+$ cd wtwrmjnt
+$ ls
+252366 pvpdv.jwz
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd pwg
+$ ls
+280845 fcsjl.fjz
+44300 sgwz.cdz
+dir snjntth
+229605 vqgsglwq
+$ cd snjntth
+$ ls
+2053 pflvsnzs
+143522 sgwz.cdz
+$ cd ..
+$ cd ..
+$ cd wcmhcfm
+$ ls
+229329 qsznhwlw.vjg
+$ cd ..
+$ cd zwhvmln
+$ ls
+dir ffpzc
+dir tjjzbf
+dir wzcq
+$ cd ffpzc
+$ ls
+dir ncnj
+37497 vqgsglwq
+$ cd ncnj
+$ ls
+40920 htbjhjq
+$ cd ..
+$ cd ..
+$ cd tjjzbf
+$ ls
+47522 mczn.spd
+$ cd ..
+$ cd wzcq
+$ ls
+56662 ffpzc.vwp
+dir snjntth
+$ cd snjntth
+$ ls
+117276 wjlmgq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd lrfcgzl
+$ ls
+267485 rsjmpph.qqz
+$ cd ..
+$ cd zshh
+$ ls
+dir ffpzc
+dir gmn
+dir snjntth
+150048 tgtlh
+32020 thfr
+72152 vqgsglwq
+$ cd ffpzc
+$ ls
+dir snjntth
+$ cd snjntth
+$ ls
+224945 dpfpz
+$ cd ..
+$ cd ..
+$ cd gmn
+$ ls
+238996 sgwz.cdz
+$ cd ..
+$ cd snjntth
+$ ls
+86775 dzdfc.vqq
+19560 vshcmjj
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd zjbp
+$ ls
+dir fcsjl
+41522 nlvpb.fpf
+dir nmtjtd
+$ cd fcsjl
+$ ls
+276802 fcsjl.psm
+197934 sgwz.cdz
+$ cd ..
+$ cd nmtjtd
+$ ls
+47477 dvqmqlgw.ths
+51081 vqgsglwq
diff --git a/day07/examples/test.txt b/day07/examples/test.txt
new file mode 100644
index 0000000..09a921e
--- /dev/null
+++ b/day07/examples/test.txt
@@ -0,0 +1,23 @@
+$ cd /
+$ ls
+dir a
+14848514 b.txt
+8504156 c.dat
+dir d
+$ cd a
+$ ls
+dir e
+29116 f
+2557 g
+62596 h.lst
+$ cd e
+$ ls
+584 i
+$ cd ..
+$ cd ..
+$ cd d
+$ ls
+4060174 j
+8033020 d.log
+5626152 d.ext
+7214296 k