Skip to content

Commit c14a827

Browse files
authored
Merge pull request #46 from weaponsforge/feat/weaponsforge-44
refactor: organize aoc-related functions
2 parents 4ac7ab8 + 863e171 commit c14a827

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+451
-370
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ It follows the directory structure:
4848
> [!NOTE]
4949
> 📂 dist<br>
5050
> 📂 src<br>
51-
> └─ 📂 utils<br>
51+
> └─ 📂 aoc<br>
5252
> └─ 📂 sample<br>
5353
> └─ 📂 2024<br>
5454
> └─── 📂 2024-12-01<br>
@@ -77,7 +77,7 @@ Each Advent of Code (AOC) event quiz has its folder under **`"/src/<YEAR>/<YYYY-
7777

7878
#### Other Items
7979

80-
- **/src/utils**: Folder containing generic utility helper functions
80+
- **/src/aoc**: 🗃️ Folder containing generic utility and common AoC helper functions
8181
- **/src/dist**: Folder containing the JavaScript files compiled from TypeScript (not committed to the repository)
8282
- **/src/sample**: Miscellaneous random examples
8383
- **/src/index.ts**: Exports all solutions to AOC quiz answer functions

src/2024/2024-12-01/lib/fileReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import { readFile, directory } from '@/utils/file.js'
2+
import { readFile, directory } from '@/aoc/file/utils.js'
33

44
export type arrayLists = {
55
list1: string[];

src/2024/2024-12-01/lib/listTotalDistance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { arrangeArray, ARRAY_ORDERING } from '@/utils/arrays.js'
1+
import { arrangeArray, ARRAY_ORDERING } from '@/aoc/array/utils.js'
22

33
/**
44
* Calculates the total distance between the smallest value-pairs from list `a` and list `b`

src/2024/2024-12-02/lib/fileReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import { readFile, directory } from '@/utils/file.js'
2+
import { readFile, directory } from '@/aoc/file/utils.js'
33

44
/**
55
* Reads the quiz's input file into two (2) string arrays

src/2024/2024-12-03/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import { directory, readFile } from '@/utils/file.js'
2+
import { directory, readFile } from '@/aoc/file/utils.js'
33
import { extractMultiply, extractMultiplyCondition } from './lib/extractMultiply.js'
44

55
const dir = directory(import.meta.url)

src/2024/2024-12-04/lib/wordCheckerUtils.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
export type CharacterArray = string[][]
2-
3-
interface CoordinateBase {
4-
x: number;
5-
y: number;
6-
}
7-
8-
interface Coordinate extends CoordinateBase {
9-
direction: 1 | -1;
10-
}
11-
12-
interface CoordinateData {
13-
xDirection: 1 | -1;
14-
yDirection: 1 | -1;
15-
data: CharacterArray
16-
}
1+
import type {
2+
Coordinate,
3+
Point,
4+
CoordinateData
5+
} from '@/aoc/point/types.js'
176

187
/**
198
* Finds the `WORD` input parameter in the vertical directions (up/down) from an (x,y) coordinate
@@ -23,11 +12,11 @@ interface CoordinateData {
2312
* @param coord.direction {number} Up or down letter-checking direction
2413
* - `-1` for "up" going to (0,0)
2514
* - `1` for "down" going to (N,N) from the `coord`
26-
* @param fullData {CharacterArray} 2D array of strings consisting of letters per item
15+
* @param fullData {string[][]} 2D array of strings consisting of letters per item
2716
* @param WORD {string} Word to find
2817
* @returns {boolean} Flag indicating the existence of the `WORD`
2918
*/
30-
export const checkVertical = (coord: Coordinate, fullData: CharacterArray, WORD: string): boolean => {
19+
export const checkVertical = (coord: Coordinate, fullData: string[][], WORD: string): boolean => {
3120
let yIndex = coord.y
3221
let subWord = ''
3322

@@ -79,11 +68,11 @@ export const checkHorizontal = (coord: Coordinate, rowData: string[], WORD: stri
7968
* @typedef param {CoordinateData} Direction and data object
8069
* @param param.xDirection {number} `-1` for "left" going to (0,0) or `1` for "right" going to (N,N) from the `coord`
8170
* @param param.yDirection {number} `-1` for "up" going to (0,0) or `1` for "down" going to (N,N) from the `coord`
82-
* @param param.data {CharacterArray} 2D string array containing the input text
71+
* @param param.data {string[][]} 2D string array containing the input text
8372
* @returns {boolean} Flag indicating the existence of the `WORD`
8473
* @param WORD {string} Word to find
8574
*/
86-
export const checkDiagonal = (coord: CoordinateBase, param: CoordinateData, WORD: string): boolean => {
75+
export const checkDiagonal = (coord: Point, param: CoordinateData, WORD: string): boolean => {
8776
let xIndex = coord.x
8877
let yIndex = coord.y
8978
let subWord = ''

src/2024/2024-12-04/lib/wordCount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { checkVertical, checkHorizontal, checkDiagonal } from './wordCheckerUtil
22

33
/**
44
* Counts the number of occurence of the `WORD` from a set of input
5-
* @param data {CharacterArray} 2D string array containing the input text
5+
* @param data {string[][]} 2D string array containing the input text
66
* @param WORD_TO_FIND {string} Word to find
77
* @returns {number} Number of `WORD`s
88
*/

src/2024/2024-12-04/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import { directory, readFile } from '@/utils/file.js'
2+
import { directory, readFile } from '@/aoc/file/utils.js'
33
import { wordCount } from './lib/wordCount.js'
44
import { countMASword } from './lib/xmasCount.js'
55

src/2024/2024-12-05/lib/fileReader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
2-
import { directory, readFile } from '@/utils/file.js'
3-
import { uniformArrayElements } from '@/utils/arrays.js'
2+
import { directory, readFile } from '@/aoc/file/utils.js'
3+
import { uniformArrayElements } from '@/aoc/array/utils.js'
44

55
export type Rules = Record<number, number[]>
66

src/2024/2024-12-05/lib/fixOrderingUpdates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isOrderedReport } from './orderedUpdates.js'
2-
import { arrayMiddleIndex, uniformArrayElements } from '@/utils/arrays.js'
2+
import { arrayMiddleIndex, uniformArrayElements } from '@/aoc/array/utils.js'
33

44
import type { Rules } from './fileReader.js'
55
import type { QuizData } from './fileReader.js'

0 commit comments

Comments
 (0)