diff --git a/README.md b/README.md
index 2d1c887..0023ed9 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,7 @@ This repository contains solutions and a local development environment for the [
2024
- Day 1: Historian Hysteria [[link]](/src/2024/2024-12-01/README.md)
+- Day 2: Red-Nosed Reports [[link]](/src/2024/2024-12-02/README.md)
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 4be77df..b11b0bf 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -8,16 +8,17 @@ export default [
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
- { ignores: ['node_modules/*'] },
+ { ignores: ['node_modules/**'] },
{
rules: {
- 'no-unused-vars': 'error',
+ // 'no-unused-vars': 'off',
'no-undef': 'error',
+ 'no-trailing-spaces': 'error',
+ '@typescript-eslint/no-unused-vars': ['error'],
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'never'],
- 'no-trailing-spaces': 'error',
'comma-dangle': ['error', 'never'],
'object-curly-spacing': ['error', 'always'],
'eol-last': ['error', 'always']
diff --git a/src/2024/2024-12-01/README.md b/src/2024/2024-12-01/README.md
index 3eea51f..1d31fa3 100644
--- a/src/2024/2024-12-01/README.md
+++ b/src/2024/2024-12-01/README.md
@@ -47,6 +47,7 @@ To find the total distance between the left list and the right list, add up the
Your actual left and right lists contain many location IDs. What is the total distance between your lists?
+> [!TIP]
> **Your puzzle answer was** 2086478.
---
@@ -85,4 +86,5 @@ So, for these example lists, the similarity score at the end of this process is
Once again consider your left and right lists. What is their similarity score?
+> [!TIP]
> **Your puzzle answer was** 24941624.
\ No newline at end of file
diff --git a/src/2024/2024-12-01/lib/fileReader.ts b/src/2024/2024-12-01/lib/fileReader.ts
index 1ca5c2d..f3aa32a 100644
--- a/src/2024/2024-12-01/lib/fileReader.ts
+++ b/src/2024/2024-12-01/lib/fileReader.ts
@@ -1,5 +1,5 @@
import path from 'path'
-import { readFile, currentDirectory } from '@/lib/file.js'
+import { readFile, currentDirectory } from '@/utils/file.js'
export type arrayLists = {
list1: string[];
diff --git a/src/2024/2024-12-01/lib/listTotalDistance.ts b/src/2024/2024-12-01/lib/listTotalDistance.ts
index dc24cca..79d3a87 100644
--- a/src/2024/2024-12-01/lib/listTotalDistance.ts
+++ b/src/2024/2024-12-01/lib/listTotalDistance.ts
@@ -1,4 +1,4 @@
-import { arrangeArray, ARRAY_ORDERING } from '@/lib/arrays.js'
+import { arrangeArray, ARRAY_ORDERING } from '@/utils/arrays.js'
/**
* Calculates the total distance between the smallest value-pairs from list `a` and list `b`
diff --git a/src/2024/2024-12-02/README.md b/src/2024/2024-12-02/README.md
new file mode 100644
index 0000000..11c87ab
--- /dev/null
+++ b/src/2024/2024-12-02/README.md
@@ -0,0 +1,74 @@
+## Day 2: Red-Nosed Reports
+
+**Source:** https://adventofcode.com/2024/day/2
+**Status:** Complete
+
+### 📘 Part 1
+
+Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office.
+
+While the [Red-Nosed Reindeer nuclear fusion/fission plant](https://adventofcode.com/2015/day/19) appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Apparently, they still talk about the time Rudolph was saved through molecular synthesis from a single electron.
+
+They're quick to add that - since you're already here - they'd really appreciate your help analyzing some unusual data from the Red-Nosed reactor. You turn to check if The Historians are waiting for you, but they seem to have already divided into groups that are currently searching every corner of the facility. You offer to help with the unusual data.
+
+The unusual data (your puzzle input) consists of many reports, one report per line. Each report is a list of numbers called levels that are separated by spaces. For example:
+
+```text
+7 6 4 2 1
+1 2 7 8 9
+9 7 6 2 1
+1 3 2 4 5
+8 6 4 4 1
+1 3 6 7 9
+```
+
+This example data contains six reports each containing five levels.
+
+The engineers are trying to figure out which reports are safe. The Red-Nosed reactor safety systems can only tolerate levels that are either gradually increasing or gradually decreasing. So, a report only counts as safe if both of the following are true:
+
+- The levels are either all increasing or all decreasing.
+- Any two adjacent levels differ by at least one and at most three.
+
+In the example above, the reports can be found safe or unsafe by checking those rules:
+
+- `7 6 4 2 1`: Safe because the levels are all decreasing by 1 or 2.
+- `1 2 7 8 9`: Unsafe because 2 7 is an increase of 5.
+- `9 7 6 2 1`: Unsafe because 6 2 is a decrease of 4.
+- `1 3 2 4 5`: Unsafe because 1 3 is increasing but 3 2 is decreasing.
+- `8 6 4 4 1`: Unsafe because 4 4 is neither an increase or a decrease.
+- `1 3 6 7 9`: Safe because the levels are all increasing by 1, 2, or 3.
+
+So, in this example, 2 reports are safe.
+
+Analyze the unusual data from the engineers. How many reports are safe?
+
+To begin, get your puzzle input (see input.txt).
+
+> [!TIP]
+> **Your puzzle answer was** 598.
+
+---
+
+### 📗 Part 2
+
+The engineers are surprised by the low number of safe reports until they realize they forgot to tell you about the **Problem Dampener**.
+
+The Problem Dampener is a reactor-mounted module that lets the reactor safety systems tolerate a single bad level in what would otherwise be a safe report. It's like the bad level never happened!
+
+Now, the same rules apply as before, except if removing a single level from an unsafe report would make it safe, the report instead counts as safe.
+
+More of the above example's reports are now safe:
+
+- `7 6 4 2 1`: Safe without removing any level.
+- `1 2 7 8 9`: Unsafe regardless of which level is removed.
+- `9 7 6 2 1`: Unsafe regardless of which level is removed.
+- `1 3 2 4 5`: Safe by removing the second level, `3`.
+- `8 6 4 4 1`: Safe by removing the third level, `4`.
+- `1 3 6 7 9`: Safe without removing any level.
+
+Thanks to the **Problem Dampener**, 4 reports are actually safe!
+
+Update your analysis by handling situations where the Problem Dampener can remove a single level from unsafe reports. How many reports are now safe?
+
+> [!TIP]
+> **Your puzzle answer was** 634.
diff --git a/src/2024/2024-12-02/input.txt b/src/2024/2024-12-02/input.txt
new file mode 100644
index 0000000..7e17095
--- /dev/null
+++ b/src/2024/2024-12-02/input.txt
@@ -0,0 +1,1000 @@
+8 10 13 14 12
+40 42 45 47 49 49
+45 48 51 52 55 58 62
+61 63 64 67 69 72 74 81
+95 97 98 99 98 99
+84 85 88 89 88 85
+20 23 21 24 25 28 31 31
+15 16 18 17 18 22
+31 32 30 32 34 39
+72 74 74 77 78
+2 4 4 5 8 9 6
+68 69 72 72 72
+73 74 77 77 80 82 83 87
+11 13 15 16 16 17 23
+73 74 78 81 84
+51 52 54 58 59 56
+40 42 46 48 51 53 53
+18 19 20 21 25 29
+21 22 23 27 28 31 38
+3 5 8 9 14 15
+1 4 5 6 13 12
+50 51 57 59 60 60
+42 45 48 54 57 61
+17 20 23 24 29 31 37
+50 49 50 51 52 54 55
+9 7 8 10 13 16 15
+16 14 17 18 18
+49 47 50 53 55 59
+21 20 23 26 27 30 35
+78 77 78 81 84 82 85 86
+94 91 94 93 96 93
+13 12 14 12 13 13
+19 17 18 20 19 23
+57 54 57 55 57 64
+86 84 84 85 88
+16 14 14 16 15
+74 72 74 74 77 79 80 80
+51 48 49 49 53
+26 24 27 29 30 33 33 38
+76 73 77 79 80 82
+78 75 78 79 83 80
+65 64 67 68 72 72
+11 9 12 15 19 20 21 25
+30 29 33 34 36 37 38 43
+15 12 14 16 23 26
+78 77 82 85 82
+59 58 65 66 66
+53 52 54 56 62 64 68
+54 51 54 56 63 64 71
+47 47 48 49 51 52
+21 21 24 27 28 31 28
+13 13 16 17 18 21 21
+5 5 7 10 13 16 17 21
+3 3 4 6 12
+44 44 41 42 44 45 48 51
+76 76 73 76 79 82 80
+81 81 83 85 84 84
+46 46 43 46 50
+81 81 83 85 88 85 88 95
+10 10 10 13 14
+75 75 75 77 76
+43 43 43 45 45
+92 92 93 93 97
+52 52 53 53 59
+77 77 78 82 85
+20 20 24 26 28 26
+4 4 8 9 12 12
+43 43 46 50 54
+45 45 46 50 51 56
+67 67 68 69 70 77 78 80
+57 57 62 65 63
+53 53 60 63 65 65
+67 67 73 74 76 80
+8 8 14 16 17 19 26
+9 13 14 17 20 23
+84 88 91 94 97 94
+19 23 24 26 29 30 30
+57 61 64 66 68 69 73
+28 32 33 35 42
+17 21 23 26 25 26 28
+77 81 79 80 82 83 85 83
+87 91 92 89 92 92
+39 43 42 43 47
+39 43 46 44 50
+54 58 59 59 61 64
+61 65 65 66 68 65
+62 66 68 69 70 70 70
+15 19 19 22 24 28
+67 71 73 73 74 79
+75 79 83 84 86 87 89 90
+13 17 19 20 24 26 23
+38 42 44 47 50 54 55 55
+22 26 30 31 33 37
+40 44 47 50 52 53 57 64
+27 31 34 41 42
+44 48 50 51 56 53
+46 50 51 54 55 62 63 63
+54 58 61 66 67 71
+45 49 52 54 56 62 64 70
+7 13 15 17 19 21 22
+69 74 76 79 82 79
+69 75 78 81 83 85 85
+45 50 51 52 55 58 62
+29 36 39 41 42 49
+50 55 54 57 59 62 65
+32 37 35 38 40 42 40
+50 57 58 57 60 61 61
+79 86 89 91 89 93
+30 35 33 36 41
+6 13 15 16 16 18
+20 25 28 31 31 32 29
+87 92 93 96 96 98 98
+15 20 20 23 27
+11 17 20 23 23 28
+52 59 60 64 67
+2 8 9 10 14 15 16 13
+76 81 84 85 89 91 91
+43 48 51 55 57 60 63 67
+8 14 15 17 21 27
+4 9 10 16 18 19 22 25
+71 78 84 85 87 84
+4 11 14 20 22 22
+37 42 47 48 49 53
+72 79 82 87 90 97
+58 57 54 53 50 47 44 46
+83 81 78 77 77
+40 37 36 33 32 31 27
+34 31 28 26 23 22 19 13
+50 47 44 45 43
+33 30 29 32 35
+89 88 85 83 80 79 81 81
+47 46 47 46 42
+59 57 55 52 49 46 48 41
+85 82 82 80 78 77 74 73
+71 68 68 65 64 63 61 64
+92 89 86 85 84 84 84
+97 96 93 93 92 91 87
+76 74 71 71 70 63
+38 37 33 32 29 26 25
+54 52 49 46 42 43
+47 46 44 40 40
+99 98 94 91 88 87 84 80
+86 85 82 78 77 71
+19 18 17 11 10
+62 60 58 52 53
+46 44 37 36 35 32 32
+50 47 45 39 35
+74 71 70 67 60 57 51
+87 90 89 87 85 83
+28 29 28 25 24 23 21 24
+44 46 44 41 38 35 35
+70 71 70 67 64 63 59
+49 52 49 46 40
+88 89 87 88 87 85
+44 47 45 42 43 41 43
+3 5 8 7 6 3 3
+85 88 91 88 85 81
+55 58 55 54 57 54 47
+16 18 16 15 15 14 13
+75 77 75 75 78
+43 46 43 40 38 38 36 36
+94 95 94 91 88 88 87 83
+68 70 69 67 64 64 58
+79 82 78 77 75 74 72
+51 53 49 47 48
+43 45 42 40 38 34 32 32
+43 44 43 41 39 35 32 28
+55 57 53 51 44
+43 45 44 37 36 34
+88 90 88 85 78 76 79
+57 60 57 52 50 50
+43 46 40 39 38 37 36 32
+95 96 89 88 81
+82 82 81 78 76 73 70 69
+73 73 72 71 69 68 71
+43 43 42 41 38 38
+23 23 20 17 13
+42 42 40 37 35 28
+10 10 8 6 9 8
+40 40 39 41 42
+6 6 4 6 5 5
+31 31 30 32 30 26
+35 35 34 32 34 33 32 25
+27 27 25 24 24 23 21
+54 54 52 49 49 48 45 47
+56 56 56 55 55
+51 51 48 48 47 43
+19 19 19 17 11
+54 54 52 49 46 42 41
+65 65 64 60 61
+24 24 23 19 16 13 13
+64 64 60 57 53
+88 88 87 86 83 79 73
+48 48 42 39 37 36 33
+76 76 71 70 69 68 69
+26 26 24 19 19
+21 21 18 16 11 9 5
+46 46 45 43 41 40 33 26
+32 28 27 26 25 24
+60 56 55 52 51 49 51
+54 50 49 47 46 46
+42 38 35 34 32 29 25
+94 90 87 86 83 81 74
+58 54 53 50 49 52 50
+52 48 46 44 46 49
+29 25 23 21 18 17 20 20
+23 19 18 21 19 17 13
+37 33 32 34 28
+82 78 75 75 73 71 68 65
+31 27 25 23 22 19 19 22
+55 51 48 48 48
+38 34 32 29 27 27 26 22
+55 51 50 48 48 47 42
+81 77 75 71 70
+43 39 37 33 31 34
+55 51 50 49 48 47 43 43
+19 15 11 9 6 2
+71 67 66 62 61 58 52
+41 37 36 35 30 29 26 23
+53 49 43 40 37 39
+88 84 82 79 74 72 70 70
+97 93 87 85 81
+96 92 91 84 83 78
+68 63 61 59 57 56
+98 91 90 87 85 83 84
+31 24 23 21 18 17 17
+70 64 63 61 57
+61 54 52 49 46 43 37
+23 17 15 13 12 11 14 13
+49 42 39 41 39 38 40
+33 26 29 27 26 26
+37 31 32 30 28 25 21
+70 63 60 63 60 57 56 50
+56 50 48 47 44 41 41 39
+39 34 34 33 30 28 27 29
+63 56 54 54 54
+86 80 80 77 75 74 71 67
+24 18 15 14 12 11 11 6
+69 64 62 60 56 55
+82 76 72 71 69 66 63 65
+85 78 74 72 72
+78 72 68 67 63
+79 74 72 70 68 64 59
+52 47 41 40 39 36 34 31
+46 41 40 34 31 28 31
+26 19 16 14 9 9
+72 67 62 60 56
+85 78 72 69 68 63
+83 80 77 77 74 74
+54 50 48 45 41 38 34
+60 57 59 62 60
+41 38 40 47 50 52 56
+74 72 73 71 74 75 77 77
+67 65 63 61 60 56 55 48
+5 9 10 11 8 10 14
+71 70 73 74 71 75
+81 78 77 77 76 74
+56 56 53 55 56 60
+74 77 78 80 81 84 84 83
+62 62 59 57 53
+79 85 85 88 90 94
+32 30 31 33 33 34 35 35
+3 7 6 9 10 12 14 14
+37 39 36 33 33
+51 52 47 46 45 44 44
+56 52 50 49 49 47 45 46
+52 58 61 62 64 68
+46 46 43 41 40 37 34
+49 49 50 52 53 55 58 58
+35 32 33 37 38 37
+48 45 47 49 48 50 51
+8 10 10 11 11
+47 48 51 53 55 54
+40 37 38 44 50
+51 58 60 63 60 67
+33 34 37 44 46 48 51 55
+25 22 19 20 19
+66 69 70 73 76 79 77 83
+72 72 71 70 63 62 58
+64 62 61 60 59 56 58 51
+18 19 16 15 12 9
+4 1 4 5 6 9 10
+76 70 68 64 67
+40 44 45 48 52 54
+61 68 70 77 79 81 81
+14 12 12 14 17 19 20 21
+29 33 35 36 40
+90 90 88 88 86 85 84 87
+19 24 27 30 37 41
+64 63 61 57 56 55 52 53
+75 75 72 70 64 61 64
+66 69 73 74 78
+56 57 54 51 51 49 45
+56 56 57 63 66
+9 13 16 19 21 22 22
+65 62 63 68 68
+88 82 80 77 74
+74 72 73 80 82 84 87 89
+67 62 60 58 57 59 55
+60 63 61 57 52
+63 67 70 77 77
+71 68 69 68 67 64 61 62
+55 59 60 60 62 60
+59 59 56 54 53 53 53
+25 25 23 25 23 20 23
+59 53 52 50 50 49 47
+57 57 59 61 63 65 70
+16 16 17 18 21 21 22 22
+36 30 29 32 33
+52 51 49 42 40 40
+34 36 39 41 42 40 40
+97 90 89 87 84 82 79 79
+15 11 9 7 4 4
+21 25 27 24 27 30 27
+29 30 29 28 27 30 23
+18 22 26 27 30 34
+35 39 42 44 45 48 52 58
+10 13 15 16 17 20 17 21
+29 30 32 33 35 36 41 42
+91 87 84 82 75 74 71 70
+93 93 91 93 91 90 90
+64 64 61 60 58 53 53
+41 44 42 44 43 42 38
+56 57 55 51 49 45
+67 73 76 78 79 78
+79 79 81 83 87 88 88
+57 60 57 56 54 49
+34 34 35 36 38 36 38 39
+64 63 60 54 50
+88 89 86 86 89
+17 16 19 23 24 27 31
+91 87 86 83 80 77 73
+23 21 23 24 26 29 34
+53 51 48 47 45 43 39 36
+13 20 22 26 29 30 33 31
+91 90 87 85 81 81
+15 16 15 12 11 11 8 8
+79 74 71 68 67 66 62
+59 59 58 51 45
+38 40 45 48 51 51
+54 56 54 51 49 49 48 42
+9 11 12 15 17 21
+32 26 25 20 19 19
+36 43 46 48 48 49
+9 7 7 9 12 17
+17 21 24 27 32 33 35 36
+78 75 73 72 70 69 66 66
+51 46 44 41 39 38 34 34
+96 96 93 90 88 85 81 83
+21 27 30 32 33 36 41 38
+46 48 45 42 41 38 34
+87 84 86 84 87 90 96
+80 80 81 85 90
+33 38 41 40 42 44 45 44
+66 60 58 54 53
+26 19 16 14 10 4
+40 44 47 47 49 52 56
+71 76 77 78 79 79
+92 92 91 92 95 93
+73 70 68 63 61 60 61
+32 32 34 39 39
+53 49 46 43 40 38 36 35
+68 71 69 67 66 61 55
+57 61 68 69 71 75
+73 77 79 82 84 85 87 85
+7 9 10 11 14 13 16 14
+15 10 12 9 8 1
+62 63 61 54 52
+31 35 36 38 39 38 39
+79 77 76 75 74 73 70 63
+59 58 60 61 62 67 65
+80 76 75 74 73 71 66 68
+59 64 67 71 73 80
+52 46 43 43 39
+67 62 59 55 51
+55 59 62 62 65 67 68 68
+92 92 89 86 85 84 83 78
+37 44 46 46 47 44
+21 17 13 11 11
+11 15 16 17 20 21 24 31
+95 91 89 86 89
+15 16 18 19 19 22
+50 50 47 44 42 45
+20 16 13 13 10 7 5 5
+13 20 21 22 28
+57 53 51 47 46 45 48
+10 10 8 6 4 1 3 2
+64 68 71 73 74 80 86
+10 16 18 16 19 19
+87 90 86 84 84
+29 22 20 21 19 16
+2 3 5 9 15
+67 70 67 66 63 63 62
+66 63 67 70 72 74 75 75
+98 98 96 95 94 94
+64 68 70 73 75 78 80 82
+41 41 37 34 33 31 31
+84 84 85 89 90 91 93 97
+17 17 13 12 7
+20 13 10 7 7 5 5
+94 96 94 93 92 89 91
+38 38 41 43 47 49 51
+79 76 73 72 70 68 65
+50 47 44 41 38
+20 18 15 14 13 10 8 7
+75 78 80 83 84 86
+88 90 92 95 97 98
+58 55 52 51 50 49
+87 89 91 93 95 97
+4 6 7 10 11
+33 34 35 36 38 40 43 44
+85 83 80 78 77 76 73 71
+56 55 54 51 50 47
+23 25 27 30 31 33
+22 19 16 13 12 11 9
+13 11 8 5 4
+61 63 64 67 70 72
+97 95 92 89 87
+72 73 76 78 81 84
+62 59 58 55 52
+73 71 69 68 66 65 64 62
+58 60 61 63 65 66 68
+85 87 89 90 93 95
+32 33 35 36 38 39 40 42
+63 64 66 67 70 71
+71 68 66 63 61
+89 90 91 94 95 96
+66 64 62 61 58
+34 35 38 39 41 43 44 46
+56 58 60 62 65 68 69 72
+51 50 47 45 43 42 40
+36 37 40 43 45 46
+57 55 54 51 50
+72 75 78 80 82 84 87 90
+37 40 41 42 43 45 47
+58 61 64 67 68
+28 25 22 20 18 17 14 13
+37 34 31 29 27 25
+48 50 53 56 57 58 61 62
+90 87 84 83 82 80
+85 84 81 79 76 73
+71 73 75 78 79 81 82
+92 91 88 86 84 82
+41 40 39 38 35 34
+5 7 8 10 12 15 16
+24 25 27 28 31 32
+14 13 11 10 9 8 5
+39 41 44 46 48
+13 10 7 6 3 2
+2 4 7 10 11 12 13 16
+33 30 29 27 25 24 23
+30 33 36 37 38 41 43 46
+67 64 61 58 57 54
+32 33 35 38 41 42 44 45
+17 14 12 10 8 5 4 2
+44 43 41 38 35 33 32 29
+25 28 31 32 35 37
+28 30 33 34 37 40
+19 16 15 13 12
+18 17 14 11 10
+82 80 77 74 73 71
+98 96 94 93 90 89 88
+56 53 51 50 49 47 45 44
+26 29 30 32 34 35 36
+44 47 49 50 53
+72 74 75 78 81 84 85
+55 53 52 51 49
+80 77 76 75 72 69 67
+47 48 50 52 53 56 58 60
+96 95 94 91 89 87 84 81
+11 14 16 19 21 23 26 29
+5 8 10 12 15 16 19
+62 64 65 66 67
+41 40 38 36 34 32 29
+66 69 71 72 75
+7 8 11 14 15 18 19 20
+49 48 46 43 41 38 36
+94 93 90 89 87 84 81
+47 50 51 53 55 57 58 59
+25 22 19 18 16 14 12 10
+65 64 61 59 56 54 52 49
+54 55 57 58 60 63 64 65
+59 61 62 63 66 69
+71 68 65 62 60 57 56
+34 35 38 41 44 47 49 51
+35 36 38 39 42 43
+75 78 81 82 85 88 90 93
+54 57 60 63 66
+3 6 7 10 13 14 16
+44 42 40 38 36
+67 66 65 64 62 60
+21 22 24 27 28 29 31 33
+1 2 3 5 8 11 13
+62 64 67 68 70 72 74
+82 83 84 85 88
+55 57 59 62 63 64
+31 28 27 24 23 22 19
+12 15 18 19 20
+7 9 11 14 15 18 19 22
+28 25 24 21 18 15 12
+80 77 75 72 71 68 67
+32 30 28 27 25
+50 52 55 57 59 60
+24 22 19 17 16 13 10 7
+18 20 23 26 27 28 29 32
+75 77 80 81 82 83
+84 82 81 78 75 73 72 71
+47 46 45 42 40 39 36 33
+24 22 21 20 17 15 12
+22 24 25 28 31
+40 38 36 35 34 31 28
+3 5 6 7 9
+31 33 36 39 42 43 46
+70 69 68 67 64 61 60 57
+71 72 74 77 80
+81 82 85 86 89 92 93 94
+45 47 50 52 55 56 59 62
+69 67 66 65 63 62 59
+65 63 61 60 59 56 53
+64 62 59 56 54 51 48 45
+45 43 41 38 35 33 31 29
+13 16 18 20 22 23 24 25
+61 59 56 53 51 48 47
+18 21 23 25 27 28 30 32
+68 65 63 60 57
+51 53 55 56 58 61 64 65
+80 82 84 87 90
+37 39 41 42 44
+81 83 85 86 88
+85 87 90 91 93
+19 16 15 13 11 8 6
+36 35 33 31 29
+43 41 40 38 37
+25 26 28 31 33 36 37 40
+70 68 67 65 63 60 58 56
+2 5 7 10 11 14
+61 59 57 56 55
+44 42 41 39 36 33 30
+80 81 83 85 88 89 92 93
+41 42 43 44 46 49 50 51
+3 6 7 10 13
+95 94 93 91 88 87
+84 82 81 78 76
+81 83 84 86 87 89 92
+46 45 42 41 38
+43 45 48 50 51 53
+69 68 65 62 59
+83 82 79 78 76 73 70
+17 18 21 22 25 28 29 31
+64 66 67 70 71 72 74 77
+69 68 67 64 61 59
+50 47 45 42 40 38
+70 73 76 79 80 82 84 86
+25 22 19 18 15 13 11
+83 80 78 77 76 73 70 69
+46 48 49 50 51
+44 46 48 50 51 53 56 59
+53 51 48 45 42 41 38
+49 51 52 54 57
+24 22 19 16 14 12 10
+67 69 72 75 78
+9 6 5 3 1
+8 11 14 16 17 20 23 26
+32 33 35 37 39 42 45 46
+84 82 79 78 77 74 71 70
+45 46 49 52 54 56 58 60
+34 33 30 29 27 26 24 23
+65 67 68 71 72 75 76 79
+3 6 9 12 15 17
+29 27 26 25 23 20 19 18
+61 60 58 56 54 51 48 45
+51 52 54 57 59
+52 55 58 60 63 66
+40 43 45 47 49
+73 71 70 68 66 64
+79 77 74 72 70
+77 76 74 72 69 68 66 63
+57 56 54 53 50 49
+25 22 21 20 18 17 15
+82 81 78 75 74 71
+89 87 86 85 82 79
+38 35 34 32 30 27 26
+65 68 70 73 74 76
+49 50 51 52 54
+63 65 67 69 72 74 76
+15 16 18 19 22 24 25
+52 50 47 45 42
+76 75 73 71 68 65 62
+59 58 57 55 54 53
+71 68 66 63 62 60
+64 62 59 57 54
+19 16 13 12 9 8
+86 87 89 90 92
+74 71 69 68 66
+65 64 63 61 58 56
+67 64 61 60 58 56
+78 79 80 81 84 86 89
+12 14 17 20 22 23
+41 42 44 47 48 49 52 54
+40 39 38 37 35 32
+13 14 16 18 21
+14 15 16 17 18 19
+83 84 85 87 89 90 93
+38 36 34 33 32 29 26 24
+79 76 73 71 69
+73 72 69 66 64
+92 89 87 85 82
+68 65 63 62 60
+12 13 15 18 21 24 27
+87 88 91 94 96
+75 74 72 70 68 67 65
+79 81 84 87 90 93
+48 50 51 54 55 58 60 61
+66 69 71 74 75 78
+48 46 44 41 40 37 35
+46 48 49 50 51 52 54 55
+82 85 87 90 93 94 97
+79 76 73 70 69 68
+90 87 85 83 82 80 78
+47 49 50 51 52
+64 63 60 59 58 56 53
+72 71 69 67 66 64
+59 58 56 54 53 52 50 48
+39 42 45 48 51 52 54
+40 41 43 46 49 50 52
+53 55 57 58 60 62 64 67
+27 24 22 20 18 16 14 13
+17 14 12 10 8 7 6
+1 3 6 8 11
+73 70 68 66 65 63
+63 60 59 58 55 52
+69 68 66 64 63 62 60
+29 31 32 34 36 37 38
+66 67 69 71 74 76 78 79
+73 72 71 68 67 65
+97 94 91 90 88
+13 14 16 17 19 22 24
+33 36 39 40 43 44 45
+24 21 20 17 14 11 8 7
+34 35 38 39 42 45 46 47
+63 66 67 68 71 72 75 77
+71 73 75 78 80 82 84 87
+38 40 41 43 44 45 47 49
+79 77 74 72 69 67 66
+49 50 52 53 56
+63 65 68 71 73 74 77 78
+67 70 71 73 74 77 79
+70 67 66 64 61 60 59 56
+27 29 31 33 34
+53 56 59 60 63 66 69
+54 53 50 49 48 47 46
+23 22 20 19 17
+31 33 36 39 42 44
+83 80 78 77 74 73 70
+90 87 85 82 81
+74 71 68 65 63 60 57 54
+38 41 44 47 48 51 54
+28 27 25 23 22 20
+84 85 88 90 93 95 96
+62 65 68 69 71
+90 88 85 82 80 78
+19 18 16 14 11 8 6
+62 60 58 56 55 54
+79 82 83 86 87 89 92
+42 40 38 37 35
+7 10 11 12 14 16 18
+85 88 91 92 94 95 98 99
+43 45 46 48 51 53 55
+18 21 24 27 29 32 34
+67 69 72 73 76 77
+75 78 80 83 85 86
+88 85 84 81 80
+27 28 30 31 33
+89 92 93 94 96
+78 76 73 72 69 68 65 64
+71 69 67 66 63 60 58
+35 32 30 27 25 23 20 18
+6 8 11 13 15
+81 79 77 75 74 72
+68 67 64 61 59 56 54
+45 44 43 40 37 36 33 31
+91 89 87 86 84 81 80
+91 90 89 86 85 82 81
+40 42 44 45 48 51 54
+43 41 40 39 38 36 33
+16 13 11 10 7 6
+64 63 62 59 56
+23 26 28 30 33 35 37 40
+41 38 37 36 33 30
+43 41 40 39 38 35
+84 86 87 88 89 92 95
+78 76 75 74 71 68 66
+70 72 73 75 78
+30 33 34 37 40 43 46 49
+86 88 89 92 93 94 95
+31 33 35 37 40
+75 77 80 82 84 85
+63 61 59 57 54 53 52
+30 28 27 26 24
+33 35 38 40 41 43 44 45
+73 74 76 78 80 81 84 86
+61 64 67 68 69 70 72
+37 40 42 44 45 47
+44 41 40 38 37 36 34 31
+21 20 19 16 14 13 11 10
+91 90 88 85 83 80 79
+17 19 20 21 23 25
+29 30 32 34 36 39 42 45
+57 60 62 63 64 65
+64 61 59 58 57 55
+32 31 28 26 23
+65 66 67 69 72
+14 13 10 7 4
+25 24 21 20 18 15 13
+84 87 89 91 94
+73 72 69 66 64 63 60
+47 44 43 42 41 40
+25 28 30 31 32
+90 91 92 95 98
+86 83 82 80 77 75 72
+46 49 52 53 56
+50 52 54 57 60 63 64
+36 37 38 39 41 43 44 45
+31 28 25 22 20
+63 64 66 68 70 71
+71 74 75 77 79 81 84
+20 21 23 24 26 29
+69 66 64 62 60
+15 16 18 21 24 26 27 30
+32 31 29 26 23 21
+10 12 13 16 19 20 22 24
+68 69 70 73 76 78
+71 70 68 66 63 61 60 57
+88 85 82 79 77 76 75
+47 50 51 54 57 59
+12 13 16 18 21 22
+97 94 93 92 91 89 86
+89 86 85 82 81 79 77 76
+24 26 27 30 33
+91 92 93 94 97
+94 92 89 87 86 85 82
+45 46 49 51 52 54 57
+52 49 47 46 43
+65 64 62 61 58 57 56 54
+23 26 27 30 33
+78 77 74 71 68
+39 42 43 46 49
+85 87 90 93 94 96 98
+97 94 92 90 88 85 82 79
+81 79 76 75 74 72 70
+87 89 92 94 96 97
+74 77 79 80 83 85 87 90
+62 60 57 54 51 50
+84 85 87 90 92 93
+81 78 77 75 72 69 66 63
+58 61 63 65 66 69
+63 62 59 57 55 53 51
+82 85 87 90 91 93 95 98
+56 53 52 50 49 48
+59 58 55 52 51
+27 30 33 36 37 39
+30 28 27 24 22 19 17
+54 53 52 49 48 47 44 43
+10 13 14 15 17 19
+70 67 65 64 62 60
+84 83 82 80 77 76 75 73
+83 86 89 92 93 95 97 99
+21 22 23 24 27 30 33
+52 49 46 43 41
+68 65 62 61 59
+63 66 68 69 71 74 77
+72 71 68 67 66 65
+6 8 11 12 15 18 20 23
+85 84 83 80 78 75 73
+1 2 3 4 5 7
+94 91 88 86 84
+44 46 47 48 50 51 54 56
+50 53 55 56 59 62
+96 94 91 90 88 87 85
+84 82 79 76 75 74
+61 64 67 70 71 74 77 78
+80 82 85 86 88 90 92 94
+14 16 19 20 22 25
+34 35 37 40 43 45 47
+16 14 11 10 8 6 5
+86 89 92 93 95 97 98
+73 74 75 77 80 81
+22 19 18 17 16 14 12
+79 78 77 75 72 71
+19 20 21 24 26 28 30
+63 61 59 58 55 53
+34 37 39 42 44 46
+84 83 81 78 75 72 70 69
+31 34 36 39 40 43
+67 64 63 61 58 56
+56 57 58 61 63 66 69
+70 73 75 77 78
+81 84 85 87 90 93 94
+2 4 7 9 11 14 15
+25 22 20 18 16 14 11
+17 18 19 20 21 22
+35 37 40 43 44 46 47
+64 61 59 57 55 52
+95 92 90 89 87 85 84
+69 67 66 63 60 59 56 53
+73 76 79 82 84 86 87
+59 58 56 55 53 51 50
+53 56 57 60 61 63 65 67
+14 13 11 9 7
+88 86 84 82 80 78 75
+24 26 29 30 33
+63 64 65 66 69 71
+86 84 83 80 78 75 72 70
+33 32 30 29 27 24
+75 72 71 68 66 65 63
+36 38 39 41 44 46 48
+32 30 29 28 27 24 21 19
+23 21 20 18 17 14 11 10
+21 23 24 25 26 28
+56 59 62 64 65 67 70 73
+79 76 73 70 68 66 65
+77 79 81 83 85 86 87 89
+34 35 36 37 39
+41 38 37 34 33 32 31 29
+22 19 18 16 15 14
+9 12 13 16 19
+70 71 72 75 76
+25 28 31 32 34
+51 48 46 45 44 42 40 38
+20 17 15 13 10 8
+53 50 49 46 43 42 39 36
+85 88 89 90 92
+72 75 77 78 80 82 84
+61 60 57 56 53
+62 60 58 55 52 51 48 47
+97 94 93 91 88 85 84 82
+49 51 53 56 57 58
+2 3 6 8 9 10 12 13
+23 20 17 14 11
+21 23 26 29 30 32 34 35
+74 73 70 67 65
+24 21 18 16 13 12
+69 71 74 76 77
+82 80 79 76 75 73 71 70
+18 19 22 24 27 28 30
+55 58 60 63 65
+59 57 56 55 52
+55 58 60 63 65 68 69 71
+63 65 67 68 71 74 76 77
+44 41 38 35 33 30
+47 45 43 41 38 35 33
+29 30 33 34 35 37 38 39
+66 65 63 60 58 55 52
+61 64 66 68 69 70 71 74
+98 96 94 91 90
+57 59 60 63 65 68 69
+75 78 79 80 82 83 84 87
+78 80 83 85 87
+66 67 68 70 72 73 76 79
+53 50 49 47 46
+29 30 32 34 35 38 40
+72 74 75 78 80 81
+5 6 7 9 11 14 16 17
+88 87 85 82 81 79 77 76
+12 14 15 17 19 21
+74 73 72 69 66 65
+24 25 28 31 32
+62 64 65 68 69 71 73
+63 60 57 55 52 50 49
+5 8 9 11 12 15 17 20
+42 44 47 49 52 54
+28 29 30 33 34 35
+46 44 41 39 38
+85 86 87 90 92 94
+59 58 56 55 53
+82 79 77 76 74
+96 94 92 89 86 85
+51 49 46 44 41 40 37
+43 46 47 50 52
+26 23 22 19 17 15 12 9
+39 42 44 45 46
+84 83 80 78 76 75
+65 64 61 58 56 55
+10 9 8 5 4 2 1
+62 61 60 58 55 53 50
+42 40 39 37 34 32 30 27
+79 76 74 71 69 67 64
+97 96 93 90 87 85 83
+16 19 22 23 24
+48 47 46 43 40 38 36
+37 34 31 28 25 23
+44 43 41 40 38 35
+47 44 42 40 39 38 36
+27 29 32 34 36
+43 41 39 38 35
+83 82 79 77 74
+39 41 44 46 47 49 52 53
+51 48 47 45 43 41 39 37
+27 28 29 32 35
+14 15 17 20 23 26
+35 32 31 28 27 25
+62 60 57 54 53 50 49
+14 11 8 6 5
+67 65 64 63 60
+38 37 36 34 31 29 28
+4 7 10 13 14 15 18 21
+2 4 5 8 10 11
+4 7 10 13 15 16
+68 66 64 61 58
+91 89 87 86 83 81
+94 93 91 88 86 83 82
+2 5 8 10 11 13
+72 70 68 66 63 60 59 56
+70 67 64 61 58 55 52 51
+7 8 10 12 15 16 19 22
+62 60 57 55 52 50 48 45
+33 32 29 26 23 20 19
+46 47 49 50 52
+20 21 24 25 27 29
+29 32 35 37 40 41 42 44
+82 79 76 74 72 71 69 67
+68 71 74 76 79
+71 69 68 65 63 61 60 58
+15 18 20 21 23
+54 51 49 46 45
+91 88 86 84 81 79 76 74
+24 25 26 28 29 30 33
+18 21 23 25 27 29
+25 26 27 30 31
+7 9 10 13 15 16
+50 48 45 43 42 40 38
+23 25 26 28 29
+56 57 58 59 60 63 66
+35 34 32 30 27 24 23 20
+57 55 52 51 48 45 44
+80 77 76 74 72 69 68 66
+31 30 28 27 25 23 20
+94 93 92 90 89 86 85 82
+53 51 48 47 44 42 41
+4 6 8 10 11 13 16
+46 45 44 41 39 36 33 32
+62 65 66 67 68
+84 83 81 80 79
+79 76 73 72 71 70 67
+55 57 59 60 61
+92 90 88 86 84 81
+24 27 28 30 31 34 35
+86 83 80 77 74 71 68 65
+94 91 90 89 86 84 83
+55 53 52 51 50 47
+44 45 48 51 53 54 57
+22 23 26 27 28 29
+88 91 94 97 99
+71 69 67 66 65
+23 22 19 16 13 10 8
+41 43 46 48 51 53 55 57
+90 89 87 86 84
+45 43 42 39 37
+12 13 14 15 18 20 22
+56 54 51 50 48
+10 11 14 17 18 19 21
+19 22 23 24 26 28 30
+84 82 81 79 78 77 75 72
+12 15 18 20 23 26 28 31
+95 94 91 88 85 82
+47 46 45 42 39
+62 60 58 56 55
+8 11 12 13 16 19 21
+38 40 42 43 45 48
+67 68 69 71 73 74
+60 61 62 63 64 67 68
+57 58 60 63 66 67 70 71
+79 82 83 84 86 87
+68 69 72 75 78 81
+33 36 37 39 42 44 46
+21 19 17 15 12 9
+66 67 69 71 74 75 77
+93 90 89 87 86 85 84
+10 12 15 18 21 24 27 30
+61 64 67 69 72 75 78
+98 95 94 92 89
+13 11 9 7 5
+68 65 64 62 59 57 54 52
+62 59 58 56 55 54 52 51
+85 82 80 78 76 75 74
+58 55 52 50 48 46
+64 67 69 72 74 75 76
+64 61 60 58 57 55 53
+39 40 42 44 45 48 50 53
+13 15 18 21 24
+7 9 11 14 17 19
+41 38 35 33 30
+20 23 24 26 28
+72 73 74 75 77 79 80 83
+21 20 17 15 14 12 11 10
+46 49 52 55 57 58 61 64
+42 45 47 49 52
+93 92 90 88 87 84 82 80
+17 14 11 9 8 6 4
+56 57 60 63 65 67 68 70
\ No newline at end of file
diff --git a/src/2024/2024-12-02/lib/countSafeReports.ts b/src/2024/2024-12-02/lib/countSafeReports.ts
new file mode 100644
index 0000000..7b34d2b
--- /dev/null
+++ b/src/2024/2024-12-02/lib/countSafeReports.ts
@@ -0,0 +1,116 @@
+enum DIRECTION {
+ ASC = 'ascending',
+ DESC = 'descending',
+ IDLE = 'idle'
+}
+
+interface CurrentState {
+ level: number;
+ direction: DIRECTION;
+}
+
+/**
+ * Checks if a report is safe
+ * @param report {number[]} Array of reports containing levels (numbers)
+ * @returns {boolean} Flag that indicates if a report is safe
+ */
+const isReportSafe = (report: number[]): boolean => {
+ const maxSteps = 3
+ const minSteps = 1
+
+ let safeLevelsCount = 1
+
+ const currentState: CurrentState = {
+ level: report[0] as number,
+ direction: DIRECTION.IDLE
+ }
+
+ for (let i = 1; i < report.length; i += 1) {
+ const newLevel = report[i] as number
+
+ let newDirection = currentState.direction
+ const steps = Math.abs(newLevel - currentState.level)
+
+ if (newLevel > currentState.level) {
+ newDirection = DIRECTION.ASC
+ } else if (newLevel < currentState.level) {
+ newDirection = DIRECTION.DESC
+ }
+
+ if ( // There's a change in a non-IDLE direction
+ currentState.direction !== DIRECTION.IDLE &&
+ newDirection !== currentState.direction
+ ) break
+
+ // Illegal amounts of increase/decrease
+ if (steps > maxSteps || steps < minSteps) break
+
+ currentState.level = newLevel
+ currentState.direction = newDirection
+ safeLevelsCount += 1
+ }
+
+ return safeLevelsCount === report.length
+}
+
+/**
+ * Removes a single level (number) from an unsafe report until it finds a safe pattern or until all levels are removed and retried safety checking
+ * @param report {number[]} Array of reports containing levels (numbers)
+ * @returns {boolean} Flag that indicates if an unsafe report is safe or still unsafe
+ */
+const problemDampener = (report: number[]): boolean => {
+ let isSafe = false
+
+ for (let i = 0; i < report.length; i += 1) {
+ const removeLevelIndex = i
+ const reportMod = report.filter((_, index) => index !== removeLevelIndex)
+
+ if (isReportSafe(reportMod)) {
+ isSafe = true
+ break
+ }
+ }
+
+ return isSafe
+}
+
+/**
+ * Counts the number of safe reports (row)
+ * @param list {number[]} Array of arrays of reports (numbers)
+ * @param withDampener {boolean} Flag to remove one level at a time from an unsafe report and retry checking its safety
+ * @returns {number} Number of safe reports
+ */
+export const countSafeReports = (
+ list: number[][],
+ withDampener: boolean = false
+): number => {
+ let safeCount = 0
+
+ if (!Array.isArray(list)) {
+ throw new Error('Invalid input - not an array')
+ }
+
+ for (let i = 0; i < list.length; i += 1) {
+ const report: number[] = list[i] ?? []
+
+ if (!Array.isArray(report)) continue
+
+ // Reports have at least 2 levels to compare
+ if (report.length < 2) continue
+
+ // Check valid report levels (items) - all are numbers
+ if (report.filter(level => typeof level !== 'number').length > 0) continue
+
+ if (isReportSafe(report)) {
+ safeCount += 1
+ } else {
+ if (withDampener) {
+ if (problemDampener(report)) {
+ safeCount += 1
+ }
+ }
+ }
+ }
+
+ return safeCount
+}
diff --git a/src/2024/2024-12-02/lib/fileReader.ts b/src/2024/2024-12-02/lib/fileReader.ts
new file mode 100644
index 0000000..24c6b4e
--- /dev/null
+++ b/src/2024/2024-12-02/lib/fileReader.ts
@@ -0,0 +1,16 @@
+import path from 'path'
+import { readFile, currentDirectory } from '@/utils/file.js'
+
+/**
+ * Reads the quiz's input file into two (2) string arrays
+ * @returns {arrayLists} An object containing two (2) string arrays: `{ list1, list2 }`
+ */
+export const fileReader = (): number[][] => {
+ // Read quiz input file
+ const directory = currentDirectory(import.meta.url)
+ const file = readFile(path.join(directory, '..', 'input.txt'))
+
+ return file
+ .split('\n')
+ .map(row => row.split(' ').map(Number))
+}
diff --git a/src/2024/2024-12-02/quiz.test.ts b/src/2024/2024-12-02/quiz.test.ts
new file mode 100644
index 0000000..4db6fc3
--- /dev/null
+++ b/src/2024/2024-12-02/quiz.test.ts
@@ -0,0 +1,10 @@
+import { test, expect } from 'vitest'
+import { quiz20241202_01, quiz20241202_02 } from './quiz.js'
+
+test('no. of safe reports quiz', () => {
+ expect(quiz20241202_01()).toBe(598)
+})
+
+test('no. of safe reports quiz', () => {
+ expect(quiz20241202_02()).toBe(634)
+})
diff --git a/src/2024/2024-12-02/quiz.ts b/src/2024/2024-12-02/quiz.ts
new file mode 100644
index 0000000..bcc1c04
--- /dev/null
+++ b/src/2024/2024-12-02/quiz.ts
@@ -0,0 +1,28 @@
+import { fileReader } from './lib/fileReader.js'
+import { countSafeReports } from './lib/countSafeReports.js'
+
+const input = fileReader()
+
+/**
+ * Part 1/2 of the 2024-12-02 quiz
+ * @returns {number} Number of safe reports
+ */
+export const quiz20241202_01 = (): number => {
+ // Count the number of safe reports
+ const countSafe = countSafeReports(input)
+
+ console.log('NO. OF SAFE REPORTS:', countSafe)
+ return countSafe
+}
+
+/**
+ * Part 2/2 of the 2024-12-02 quiz
+ * @returns {number} Number of safe reports with the problem dampener
+ */
+export const quiz20241202_02 = (): number => {
+ // Count the number of safe reports
+ const countSafe = countSafeReports(input, true)
+
+ console.log('NO. OF SAFE REPORTS WITH DAMPENER:', countSafe)
+ return countSafe
+}
diff --git a/src/2024/2024-12-02/sample.test.ts b/src/2024/2024-12-02/sample.test.ts
new file mode 100644
index 0000000..4a10bf4
--- /dev/null
+++ b/src/2024/2024-12-02/sample.test.ts
@@ -0,0 +1,21 @@
+import { test, expect } from 'vitest'
+import { countSafeReports } from './lib/countSafeReports.js'
+
+// Sample data
+export const data: number[][] = `7 6 4 2 1
+1 2 7 8 9
+9 7 6 2 1
+1 3 2 4 5
+8 6 4 4 1
+1 3 6 7 9`
+ .split('\n')
+ .map(row => row.split(' ').map(Number))
+
+
+test('countSafeReports - demo', () => {
+ expect(countSafeReports(data)).toBe(2)
+})
+
+test('countSafeReports with Dampener - demo', () => {
+ expect(countSafeReports(data, true)).toBe(4)
+})
diff --git a/src/lib/arrays.ts b/src/utils/arrays.ts
similarity index 85%
rename from src/lib/arrays.ts
rename to src/utils/arrays.ts
index 1530c6e..c9ed0e6 100644
--- a/src/lib/arrays.ts
+++ b/src/utils/arrays.ts
@@ -1,6 +1,6 @@
export enum ARRAY_ORDERING {
- ASC, // eslint-disable-line no-unused-vars
- DESC // eslint-disable-line no-unused-vars
+ ASC,
+ DESC
}
/**
diff --git a/src/lib/file.ts b/src/utils/file.ts
similarity index 100%
rename from src/lib/file.ts
rename to src/utils/file.ts