-
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
0 parents
commit 9ec4f1e
Showing
11 changed files
with
1,537 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 |
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,161 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"project": "./tsconfig.json" | ||
}, | ||
"rules": { | ||
"no-dupe-keys": "warn", | ||
"no-duplicate-case": "warn", | ||
"no-extra-boolean-cast": "warn", | ||
"no-extra-semi": "warn", | ||
"no-func-assign": "warn", | ||
"no-import-assign": "warn", | ||
"no-invalid-regexp": "warn", | ||
"no-irregular-whitespace": "warn", | ||
"no-sparse-arrays": "warn", | ||
"no-template-curly-in-string": "warn", | ||
"no-unexpected-multiline": "warn", | ||
"no-unreachable": "warn", | ||
"no-unsafe-finally": "warn", | ||
"no-unsafe-negation": "warn", | ||
"use-isnan": "warn", | ||
"valid-typeof": "warn", | ||
"dot-location": ["warn", "property"], | ||
"dot-notation": ["warn"], | ||
"no-case-declarations": "warn", | ||
"no-empty-pattern": "warn", | ||
"no-extend-native": "warn", | ||
"no-extra-bind": "warn", | ||
"no-extra-label": "warn", | ||
"no-fallthrough": "warn", | ||
"no-floating-decimal": "warn", | ||
"no-global-assign": "warn", | ||
"no-lone-blocks": "warn", | ||
"no-loop-func": "warn", | ||
"no-multi-spaces": "warn", | ||
"no-new-wrappers": "warn", | ||
"no-octal": "warn", | ||
"no-self-assign": "warn", | ||
"no-self-compare": "warn", | ||
"no-sequences": "warn", | ||
"no-throw-literal": "warn", | ||
"no-useless-call": "warn", | ||
"no-unused-labels": "warn", | ||
"no-useless-catch": "warn", | ||
"no-with": "warn", | ||
"wrap-iife": "warn", | ||
"yoda": "warn", | ||
"no-delete-var": "warn", | ||
"no-label-var": "warn", | ||
"@typescript-eslint/no-shadow": "warn", | ||
"no-undef-init": "warn", | ||
"array-bracket-newline": ["warn", "consistent"], | ||
"array-bracket-spacing": ["warn", "always"], | ||
"block-spacing": ["warn", "always"], | ||
"brace-style": ["warn", "1tbs", { "allowSingleLine": false }], | ||
"comma-dangle": ["warn", "always-multiline"], | ||
"comma-spacing": "warn", | ||
"comma-style": ["warn"], | ||
"computed-property-spacing": "warn", | ||
"eol-last": "warn", | ||
"func-call-spacing": "warn", | ||
"func-name-matching": "warn", | ||
"func-names": ["warn", "as-needed"], | ||
"indent": ["warn", 2, { "SwitchCase": 1 }], | ||
"key-spacing": "warn", | ||
"keyword-spacing": "warn", | ||
"new-parens": "warn", | ||
"no-array-constructor": "warn", | ||
"no-lonely-if": "warn", | ||
"no-mixed-operators": "warn", | ||
"no-multiple-empty-lines": ["warn", { "max": 1 }], | ||
"no-new-object": "warn", | ||
"no-trailing-spaces": "warn", | ||
"no-unneeded-ternary": "warn", | ||
"no-whitespace-before-property": "warn", | ||
"object-curly-spacing": ["warn", "always"], | ||
"operator-assignment": "warn", | ||
"operator-linebreak": "warn", | ||
"padded-blocks": ["warn", "never"], | ||
"prefer-object-spread": "warn", | ||
"quotes": ["warn", "single"], | ||
"@typescript-eslint/semi": "warn", | ||
"semi-spacing": "warn", | ||
"space-before-blocks": "warn", | ||
"@typescript-eslint/space-before-function-paren": ["warn", { | ||
"anonymous": "never", | ||
"named": "never", | ||
"asyncArrow": "always" | ||
}], | ||
"array-element-newline": ["warn", "consistent"], | ||
"@typescript-eslint/require-await": "warn", | ||
"space-in-parens": "warn", | ||
"space-infix-ops": "warn", | ||
"space-unary-ops": "warn", | ||
"switch-colon-spacing": "warn", | ||
"wrap-regex": "warn", | ||
"arrow-body-style": ["warn", "as-needed"], | ||
"arrow-spacing": "warn", | ||
"constructor-super": "warn", | ||
"generator-star-spacing": "warn", | ||
"no-class-assign": "warn", | ||
"no-const-assign": "warn", | ||
"@typescript-eslint/no-dupe-class-members": "warn", | ||
"no-duplicate-imports": ["warn", { "includeExports": false }], | ||
"no-new-symbol": "warn", | ||
"no-this-before-super": "warn", | ||
"no-useless-computed-key": ["warn", { "enforceForClassMembers": true }], | ||
"no-useless-constructor": "off", | ||
"@typescript-eslint/no-useless-constructor": "warn", | ||
"no-useless-rename": "warn", | ||
"no-var": "warn", | ||
"object-shorthand": "warn", | ||
"prefer-arrow-callback": "warn", | ||
|
||
"prefer-rest-params": "warn", | ||
"prefer-spread": "warn", | ||
"rest-spread-spacing": ["warn", "never"], | ||
"symbol-description": "warn", | ||
"template-curly-spacing": "warn", | ||
"yield-star-spacing": "warn", | ||
"@typescript-eslint/adjacent-overload-signatures": ["warn"], | ||
"@typescript-eslint/array-type": ["warn", { "default": "array-simple" }], | ||
"@typescript-eslint/explicit-member-accessibility": ["warn", { | ||
"accessibility": "explicit", | ||
"overrides": { | ||
"accessors": "off", | ||
"constructors": "no-public", | ||
"parameterProperties": "off" | ||
} | ||
}], | ||
"@typescript-eslint/member-delimiter-style": ["warn", { | ||
"multiline": { | ||
"delimiter": "semi", | ||
"requireLast": true | ||
}, | ||
"singleline": { | ||
"delimiter": "semi", | ||
"requireLast": false | ||
} | ||
}], | ||
"@typescript-eslint/method-signature-style": ["warn", "property"], | ||
"@typescript-eslint/no-empty-interface": "warn", | ||
"@typescript-eslint/no-extraneous-class": "warn", | ||
"@typescript-eslint/no-this-alias": "warn", | ||
"@typescript-eslint/no-throw-literal": "warn", | ||
"@typescript-eslint/no-unnecessary-type-arguments": "warn", | ||
"@typescript-eslint/prefer-includes": "warn", | ||
"@typescript-eslint/prefer-optional-chain": "warn", | ||
"@typescript-eslint/prefer-string-starts-ends-with": "warn", | ||
"@typescript-eslint/type-annotation-spacing": "warn" | ||
} | ||
} |
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,4 @@ | ||
node_modules | ||
src/2022 | ||
src/2023 | ||
src/**/input.txt |
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,8 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
"editor.detectIndentation": false, | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
} | ||
} |
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,20 @@ | ||
{ | ||
"name": "aoc2022", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@types/lodash": "^4.14.191", | ||
"@types/node": "^18.11.10", | ||
"@typescript-eslint/eslint-plugin": "^5.45.0", | ||
"@typescript-eslint/parser": "^5.45.0", | ||
"chalk": "4", | ||
"chokidar": "^3.5.3", | ||
"eslint": "^8.29.0", | ||
"lodash": "^4.17.21", | ||
"ts-node": "^10.9.1", | ||
"ts-node-dev": "^2.0.0", | ||
"type-fest": "^3.3.0", | ||
"typescript": "^4.9.3" | ||
} | ||
} |
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,39 @@ | ||
import { Promisable } from 'type-fest'; | ||
import chalk from 'chalk'; | ||
|
||
|
||
export type DayFn = (input: string) => Promisable<any>; | ||
export type DayOpts = { | ||
sampleInput?: string; | ||
sampleAnswer?: any; | ||
input?: string; | ||
}; | ||
|
||
export type Day = { | ||
day: DayFn; | ||
opts: DayOpts; | ||
}; | ||
|
||
export async function runDay(day: Day) { | ||
if (typeof day.opts.sampleInput === 'string') { | ||
const output = await day.day(day.opts.sampleInput); | ||
if (output !== undefined) { | ||
console.log('Sample output:'); | ||
console.log(output); | ||
if (day.opts.sampleAnswer) { | ||
const passes = output === day.opts.sampleAnswer; | ||
console.log('Passes:', passes ? chalk.green.bold`true` : chalk.red.bold`false`); | ||
} | ||
} | ||
} | ||
|
||
if (typeof day.opts.input === 'string') { | ||
const output = await day.day(day.opts.input); | ||
if (output !== undefined) { | ||
console.log('\nReal output:'); | ||
console.log(output); | ||
} | ||
} | ||
|
||
console.log(''); | ||
} |
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,32 @@ | ||
const DAY = '2024/day3'; | ||
// read file and -w from argv | ||
|
||
import { runDay } from './day'; | ||
import chokidar from 'chokidar'; | ||
|
||
async function run(clear: boolean): Promise<void> { | ||
for (const key of Object.keys(require.cache)) { | ||
if (key.includes(__dirname)) { | ||
delete require.cache[key]; | ||
} | ||
} | ||
|
||
try { | ||
if (clear) { | ||
console.clear(); | ||
} | ||
|
||
console.log(`Running at ${new Date().toLocaleString()}`); | ||
const day = require(`./${DAY}`); | ||
await runDay(day); | ||
} catch (err) { | ||
console.error('errored', err); | ||
} | ||
} | ||
|
||
chokidar.watch(__dirname, { | ||
ignoreInitial: true, | ||
}) | ||
.on('change', () => run(true)); | ||
|
||
run(false); |
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,20 @@ | ||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { DayOpts } from 'src/day'; | ||
|
||
export function day(input: string): any { | ||
const lines = input.split('\n'); | ||
let sum = 0; | ||
|
||
for (const line of lines) { | ||
|
||
} | ||
|
||
return sum; | ||
} | ||
|
||
export const opts: DayOpts = { | ||
input: readFileSync(join(__dirname, './input.txt')).toString(), | ||
sampleInput: readFileSync(join(__dirname, './sample.txt')).toString(), | ||
sampleAnswer: 0, | ||
}; |
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 @@ | ||
export const echo = console.log; | ||
|
||
export function mapFill<T>(length: number, filler: { value: T } | ((index: number) => T)): T[] { | ||
return Array.from({ length }, (_, i) => ( | ||
'value' in filler ? filler.value : filler(i) | ||
)); | ||
} | ||
|
||
export function range(start: number, end: number): number[] { | ||
if (start > end) { | ||
throw new Error('start may not be greater than end'); | ||
} | ||
|
||
return mapFill(end - start, (i) => i + start); | ||
} | ||
|
||
export function clamp(value: number, values: { min?: number; max?: number }): number { | ||
if ('min' in values) { | ||
value = Math.max(value, values.min); | ||
} | ||
if ('max' in values) { | ||
value = Math.min(value, values.max); | ||
} | ||
|
||
return value; | ||
} |
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,19 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"display": "Node 18", | ||
|
||
"compilerOptions": { | ||
"lib": ["es2022"], | ||
"module": "commonjs", | ||
"target": "es2022", | ||
"baseUrl": ".", | ||
|
||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"moduleResolution": "node", | ||
"strictPropertyInitialization": false, | ||
"strictNullChecks": false | ||
} | ||
} |
Oops, something went wrong.