-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
105 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './run-examples' | ||
export * from './run-solution' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { existsSync, readdirSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
import { __dirname, examplePart1, examplePart2 } from './util' | ||
|
||
const runExamples = <TInput, TResult>( | ||
year: number, | ||
day: string, | ||
reader: (file: string) => TInput, | ||
part1: (data: TInput) => TResult, | ||
part2: (data: TInput) => TResult, | ||
): void => { | ||
const dirPath = join(__dirname, `../../${year}/d${day}/test-runs`) | ||
|
||
if (existsSync(dirPath)) { | ||
const testFiles = readdirSync(dirPath) | ||
|
||
testFiles.forEach(file => { | ||
const testData = reader(join(dirPath, file)) | ||
|
||
const start1 = Date.now() | ||
const valuePart1 = part1(testData) | ||
const duration1 = Date.now() - start1 | ||
|
||
const start2 = Date.now() | ||
const valuePart2 = part2(testData) | ||
const duration2 = Date.now() - start2 | ||
|
||
examplePart1(valuePart1, file, duration1) | ||
examplePart2(valuePart2, file, duration2) | ||
}) | ||
} | ||
} | ||
|
||
export { runExamples } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { join } from 'node:path' | ||
import { __dirname, solutionPart1, solutionPart2 } from './util' | ||
|
||
const runSolution = <TInput, TResult>( | ||
year: number, | ||
day: string, | ||
reader: (file: string) => TInput, | ||
part1: (data: TInput) => TResult, | ||
part2: (data: TInput) => TResult, | ||
): void => { | ||
const filePath = join(__dirname, `../../${year}/d${day}/input.txt`) | ||
const data = reader(filePath) | ||
|
||
const start1 = Date.now() | ||
const valuePart1 = part1(data) | ||
const duration1 = Date.now() - start1 | ||
|
||
const start2 = Date.now() | ||
const valuePart2 = part2(data) | ||
const duration2 = Date.now() - start2 | ||
|
||
solutionPart1(valuePart1, duration1) | ||
solutionPart2(valuePart2, duration2) | ||
} | ||
|
||
export { runSolution } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import chalk from 'chalk' | ||
import { dirname } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
const examplePart1 = <TResult>(result: TResult, testFileName: string, durationInMs: number): void => { | ||
console.log(chalk.yellow(`[EXM] (${testFileName})\t\tPart 1: ${result}\t\t${durationInMs}ms`)) | ||
} | ||
|
||
const examplePart2 = <TResult>(result: TResult, testFileName: string, durationInMs: number): void => { | ||
console.log(chalk.red(`[EXM] (${testFileName})\t\tPart 2: ${result}\t\t${durationInMs}ms`)) | ||
} | ||
|
||
const solutionPart1 = <TResult>(result: TResult, durationInMs: number): void => { | ||
console.log(chalk.green(`[SLN]\t\t\tPart 1: ${result}\t\t${durationInMs}ms`)) | ||
} | ||
|
||
const solutionPart2 = <TResult>(result: TResult, durationInMs: number): void => { | ||
console.log(chalk.blue(`[SLN]\t\t\tPart 2: ${result}\t\t${durationInMs}ms`)) | ||
} | ||
|
||
export { | ||
__dirname, | ||
examplePart1, | ||
examplePart2, | ||
solutionPart1, | ||
solutionPart2, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters