From 3fa7f52e128624a67534493c3a6a3fe61ca3dd0a Mon Sep 17 00:00:00 2001 From: AlexAegis Date: Fri, 1 Dec 2023 04:12:54 +0100 Subject: [PATCH] chore: init task for 2023 01 --- .github/badges/python/2023.json | 6 ++ .github/badges/rust/2023.json | 6 ++ .github/badges/typescript/2023.json | 6 ++ package.json | 3 +- pnpm-lock.yaml | 34 ++++++++ pnpm-workspace.yaml | 1 + readme.md | 11 ++- resources/2023/01/example.1.txt | 0 resources/2023/01/input.txt | 0 solutions/python/readme.md | 36 +++++++++ solutions/rust/readme.md | 72 +++++++++++++++++ solutions/typescript/2015/01/package.json | 1 + solutions/typescript/2015/01/tsconfig.json | 2 +- solutions/typescript/2023/01/.eslintignore | 13 +++ solutions/typescript/2023/01/.eslintrc.cjs | 6 ++ solutions/typescript/2023/01/.prettierignore | 38 +++++++++ solutions/typescript/2023/01/package.json | 79 +++++++++++++++++++ solutions/typescript/2023/01/readme.md | 9 +++ solutions/typescript/2023/01/src/bench.ts | 18 +++++ solutions/typescript/2023/01/src/p1.spec.ts | 20 +++++ solutions/typescript/2023/01/src/p1.ts | 10 +++ solutions/typescript/2023/01/src/p2.spec.ts | 20 +++++ solutions/typescript/2023/01/src/p2.ts | 10 +++ solutions/typescript/2023/01/tsconfig.json | 28 +++++++ solutions/typescript/2023/01/typedoc.json | 5 ++ solutions/typescript/2023/01/vite.config.ts | 19 +++++ solutions/typescript/2023/01/vitest.config.ts | 3 + .../lib/src/platform/bench-task.function.ts | 14 ++-- solutions/typescript/readme.md | 36 +++++++++ 29 files changed, 495 insertions(+), 11 deletions(-) create mode 100644 .github/badges/python/2023.json create mode 100644 .github/badges/rust/2023.json create mode 100644 .github/badges/typescript/2023.json create mode 100644 resources/2023/01/example.1.txt create mode 100644 resources/2023/01/input.txt create mode 100644 solutions/typescript/2023/01/.eslintignore create mode 100644 solutions/typescript/2023/01/.eslintrc.cjs create mode 100644 solutions/typescript/2023/01/.prettierignore create mode 100644 solutions/typescript/2023/01/package.json create mode 100644 solutions/typescript/2023/01/readme.md create mode 100644 solutions/typescript/2023/01/src/bench.ts create mode 100644 solutions/typescript/2023/01/src/p1.spec.ts create mode 100644 solutions/typescript/2023/01/src/p1.ts create mode 100644 solutions/typescript/2023/01/src/p2.spec.ts create mode 100644 solutions/typescript/2023/01/src/p2.ts create mode 100644 solutions/typescript/2023/01/tsconfig.json create mode 100644 solutions/typescript/2023/01/typedoc.json create mode 100644 solutions/typescript/2023/01/vite.config.ts create mode 100644 solutions/typescript/2023/01/vitest.config.ts diff --git a/.github/badges/python/2023.json b/.github/badges/python/2023.json new file mode 100644 index 000000000..31d4a6d33 --- /dev/null +++ b/.github/badges/python/2023.json @@ -0,0 +1,6 @@ +{ + "schemaVersion": 1, + "label": "Advent of Python 2023", + "message": "0/25", + "color": "red" +} diff --git a/.github/badges/rust/2023.json b/.github/badges/rust/2023.json new file mode 100644 index 000000000..c34a702bb --- /dev/null +++ b/.github/badges/rust/2023.json @@ -0,0 +1,6 @@ +{ + "schemaVersion": 1, + "label": "Advent of Rust 2023", + "message": "0/25", + "color": "red" +} diff --git a/.github/badges/typescript/2023.json b/.github/badges/typescript/2023.json new file mode 100644 index 000000000..6e3e847d9 --- /dev/null +++ b/.github/badges/typescript/2023.json @@ -0,0 +1,6 @@ +{ + "schemaVersion": 1, + "label": "Advent of TypeScript 2023", + "message": "0/25", + "color": "red" +} diff --git a/package.json b/package.json index d6640caa5..2c6f6f55f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ "solutions/typescript/2019/*", "solutions/typescript/2020/*", "solutions/typescript/2021/*", - "solutions/typescript/2022/*" + "solutions/typescript/2022/*", + "solutions/typescript/2023/*" ], "scripts": { "build": "turbo run build-lib_ build-app_ --concurrency 16 --cache-dir .cache/turbo", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66892172c..ec6335cb7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -189,6 +189,9 @@ importers: '@types/node': specifier: ^20.10.1 version: 20.10.1 + ts-node: + specifier: ^10.9.1 + version: 10.9.1(@types/node@20.10.1)(typescript@5.3.2) vite: specifier: ^5.0.4 version: 5.0.4(@types/node@20.10.1) @@ -3655,6 +3658,37 @@ importers: specifier: ^0.34.6 version: 0.34.6(@vitest/ui@0.34.6)(jsdom@23.0.1) + solutions/typescript/2023/01: + dependencies: + '@alexaegis/advent-of-code-lib': + specifier: workspace:^ + version: link:../../libs/lib + devDependencies: + '@alexaegis/eslint-config-vitest': + specifier: ^0.9.1 + version: 0.9.1 + '@alexaegis/ts': + specifier: ^0.9.1 + version: 0.9.1 + '@alexaegis/vite': + specifier: ^0.9.1 + version: 0.9.1(@types/node@20.10.1) + '@alexaegis/vitest': + specifier: ^0.9.1 + version: 0.9.1(svelte@4.2.8)(vite@5.0.4) + '@types/node': + specifier: ^20.10.1 + version: 20.10.1 + benny: + specifier: ^3.7.1 + version: 3.7.1 + vite: + specifier: ^5.0.4 + version: 5.0.4(@types/node@20.10.1) + vitest: + specifier: ^0.34.6 + version: 0.34.6(@vitest/ui@0.34.6)(jsdom@23.0.1) + solutions/typescript/libs/ecs: dependencies: '@alexaegis/advent-of-code-lib': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index e3dc73530..9a0e959ee 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -8,4 +8,5 @@ packages: - 'solutions/typescript/2020/*' - 'solutions/typescript/2021/*' - 'solutions/typescript/2022/*' + - 'solutions/typescript/2023/*' link-workspace-packages: 'deep' diff --git a/readme.md b/readme.md index d7e74ad09..28e000ec3 100644 --- a/readme.md +++ b/readme.md @@ -19,6 +19,7 @@ ## [TypeScript](./solutions/typescript) +[![2023 TypeScript Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/typescript/2023.json)](/solutions/typescript/2023/) [![2022 TypeScript Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/typescript/2022.json)](/solutions/typescript/2022/) [![2021 TypeScript Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/typescript/2021.json)](/solutions/typescript/2021/) [![2020 TypeScript Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/typescript/2020.json)](/solutions/typescript/2020/) @@ -40,7 +41,7 @@ pnpm install ```sh # Navigate to the solution -cd solutions/typescript/2022/01 +cd solutions/typescript/2023/01 pnpm p1 pnpm p2 ``` @@ -59,7 +60,7 @@ pnpm test ```sh # Navigate to the solution -cd solutions/typescript/2022/01 +cd solutions/typescript/2023/01 pnpm test ``` @@ -67,7 +68,7 @@ pnpm test ```sh # Navigate to the solution -cd solutions/typescript/2022/01 +cd solutions/typescript/2023/01 pnpm bench ``` @@ -81,7 +82,7 @@ pnpm lint ```sh # Navigate to the solution -cd solutions/typescript/2022/01 +cd solutions/typescript/2023/01 pnpm lint:tsc pnpm lint:es pnpm lint:format @@ -89,6 +90,7 @@ pnpm lint:format ## [Rust](./solutions/rust) +[![2023 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2023.json)](/solutions/rust/2023/) [![2022 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2022.json)](/solutions/rust/2022/) [![2021 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2021.json)](/solutions/rust/2021/) [![2020 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2020.json)](/solutions/rust/2020/) @@ -100,6 +102,7 @@ pnpm lint:format ## [Python](./solutions/python) +[![2023 Python Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/python/2023.json)](/solutions/python/year2023/) [![2022 Python Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/python/2022.json)](/solutions/python/year2022/) [![2021 Python Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/python/2021.json)](/solutions/python/year2021/) [![2020 Python Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/python/2020.json)](/solutions/python/year2020/) diff --git a/resources/2023/01/example.1.txt b/resources/2023/01/example.1.txt new file mode 100644 index 000000000..e69de29bb diff --git a/resources/2023/01/input.txt b/resources/2023/01/input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/python/readme.md b/solutions/python/readme.md index 2cf664168..f06b5ad06 100644 --- a/solutions/python/readme.md +++ b/solutions/python/readme.md @@ -1,5 +1,41 @@ # Advent of Code Python Solutions +## [2023](https://adventofcode.com/2023/) + +[![2023 Python Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/python/2023.json)](/solutions/python/year2023/) + + + +| Day | Part One | Part Two | +| ------ | -------- | -------- | +| Day 1 | - | - | +| Day 2 | - | - | +| Day 3 | - | - | +| Day 4 | - | - | +| Day 5 | - | - | +| Day 6 | - | - | +| Day 7 | - | - | +| Day 8 | - | - | +| Day 9 | - | - | +| Day 10 | - | - | +| Day 11 | - | - | +| Day 12 | - | - | +| Day 13 | - | - | +| Day 14 | - | - | +| Day 15 | - | - | +| Day 16 | - | - | +| Day 17 | - | - | +| Day 18 | - | - | +| Day 19 | - | - | +| Day 20 | - | - | +| Day 21 | - | - | +| Day 22 | - | - | +| Day 23 | - | - | +| Day 24 | - | - | +| Day 25 | - | - | + + + ## [2022](https://adventofcode.com/2022/) [![2022 Python Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/python/2022.json)](/solutions/python/year2022/) diff --git a/solutions/rust/readme.md b/solutions/rust/readme.md index d1591cf10..1fa677fd7 100644 --- a/solutions/rust/readme.md +++ b/solutions/rust/readme.md @@ -1,5 +1,77 @@ # Advent of Code Rust Solutions +## [2023](https://adventofcode.com/2023/) + +[![2023 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2023.json)](/solutions/rust/2023/) + + + +| Day | Part One | Part Two | +| ------ | -------- | -------- | +| Day 1 | - | - | +| Day 2 | - | - | +| Day 3 | - | - | +| Day 4 | - | - | +| Day 5 | - | - | +| Day 6 | - | - | +| Day 7 | - | - | +| Day 8 | - | - | +| Day 9 | - | - | +| Day 10 | - | - | +| Day 11 | - | - | +| Day 12 | - | - | +| Day 13 | - | - | +| Day 14 | - | - | +| Day 15 | - | - | +| Day 16 | - | - | +| Day 17 | - | - | +| Day 18 | - | - | +| Day 19 | - | - | +| Day 20 | - | - | +| Day 21 | - | - | +| Day 22 | - | - | +| Day 23 | - | - | +| Day 24 | - | - | +| Day 25 | - | - | + + + +## [2022](https://adventofcode.com/2022/) + +[![2022 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2022.json)](/solutions/rust/2022/) + + + +| Day | Part One | Part Two | +| ------ | -------- | -------- | +| Day 1 | - | - | +| Day 2 | - | - | +| Day 3 | - | - | +| Day 4 | - | - | +| Day 5 | - | - | +| Day 6 | - | - | +| Day 7 | - | - | +| Day 8 | - | - | +| Day 9 | - | - | +| Day 10 | - | - | +| Day 11 | - | - | +| Day 12 | - | - | +| Day 13 | - | - | +| Day 14 | - | - | +| Day 15 | - | - | +| Day 16 | - | - | +| Day 17 | - | - | +| Day 18 | - | - | +| Day 19 | - | - | +| Day 20 | - | - | +| Day 21 | - | - | +| Day 22 | - | - | +| Day 23 | - | - | +| Day 24 | - | - | +| Day 25 | - | - | + + + ## [2021](https://adventofcode.com/2021/) [![2021 Rust Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/rust/2021.json)](/solutions/rust/2021/) diff --git a/solutions/typescript/2015/01/package.json b/solutions/typescript/2015/01/package.json index a86d48800..70dfd65a4 100644 --- a/solutions/typescript/2015/01/package.json +++ b/solutions/typescript/2015/01/package.json @@ -66,6 +66,7 @@ "@alexaegis/vite": "^0.9.1", "@alexaegis/vitest": "^0.9.1", "@types/node": "^20.10.1", + "ts-node": "^10.9.1", "vite": "^5.0.4", "vitest": "^0.34.6" } diff --git a/solutions/typescript/2015/01/tsconfig.json b/solutions/typescript/2015/01/tsconfig.json index 14734b74d..ae184a4cb 100644 --- a/solutions/typescript/2015/01/tsconfig.json +++ b/solutions/typescript/2015/01/tsconfig.json @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/tsconfig?mark=managed-by-autotool", - "extends": "@alexaegis/ts/node", + "extends": "./node_modules/@alexaegis/ts/node.json", "compilerOptions": { "rootDir": "../../../../", "outDir": ".cache/tsc" diff --git a/solutions/typescript/2023/01/.eslintignore b/solutions/typescript/2023/01/.eslintignore new file mode 100644 index 000000000..9bad44ce0 --- /dev/null +++ b/solutions/typescript/2023/01/.eslintignore @@ -0,0 +1,13 @@ +# managed-by-autotool + +package-lock.json +node_modules +vite.config.ts.* +vitest.config.ts.* +shims +typedoc + +# sveltekit +.svelte-kit +.vercel +build diff --git a/solutions/typescript/2023/01/.eslintrc.cjs b/solutions/typescript/2023/01/.eslintrc.cjs new file mode 100644 index 000000000..1cfd8cafe --- /dev/null +++ b/solutions/typescript/2023/01/.eslintrc.cjs @@ -0,0 +1,6 @@ +// managed-by-autotool + +/** @type {import('eslint').Linter.Config} */ +module.exports = { + extends: ['../../../../.eslintrc.cjs', '@alexaegis/eslint-config-vitest'], +}; diff --git a/solutions/typescript/2023/01/.prettierignore b/solutions/typescript/2023/01/.prettierignore new file mode 100644 index 000000000..085c30e88 --- /dev/null +++ b/solutions/typescript/2023/01/.prettierignore @@ -0,0 +1,38 @@ +# managed-by-autotool +# Add files here to ignore them from prettier formatting + +# node +node_modules +package-lock.json +pnpm-lock.yaml +yarn.lock + +# build artifacts +dist +public/build +build +.svelte-kit +.vercel +typedoc + +# test artifacts +coverage +.vscode/chrome +.nyc_output +vite.config.ts.* +vitest.config.ts.* + +# turbo +.turbo + +# rust +target +*.lock + +# python +.pytest_cache + +# others +.cache +.benchmark +CHANGELOG.md diff --git a/solutions/typescript/2023/01/package.json b/solutions/typescript/2023/01/package.json new file mode 100644 index 000000000..5b9bd8651 --- /dev/null +++ b/solutions/typescript/2023/01/package.json @@ -0,0 +1,79 @@ +{ + "name": "@alexaegis/advent-of-code-2023-01", + "description": "Advent of Code 2023 01 solutions", + "version": "1.0.0", + "license": "mit", + "private": true, + "archetype": { + "platform": "node", + "framework": "adventofcode", + "language": "ts" + }, + "keywords": [ + "advent-of-code", + "javascript", + "js", + "managed-by-autotool", + "ts", + "typescript" + ], + "type": "module", + "aoc": { + "day": 1, + "year": 2023 + }, + "scripts": { + "lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "lint:depcheck_": "depcheck", + "lint:es": "turbo run lint:es_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "lint:es_": "eslint --max-warnings=0 --fix --no-error-on-unmatched-pattern .", + "lint:format": "turbo run lint:format_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "lint:format_": "prettier --cache-location .cache/prettier --plugin prettier-plugin-svelte --plugin prettier-plugin-tailwindcss --check .", + "lint:md": "turbo run lint:md_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "lint:md_": "remark --frail --no-stdout --silently-ignore .", + "lint:tsc": "turbo run lint:tsc_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "lint:tsc_": "tsc --noEmit", + "test": "turbo run test_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "test_": "vitest --passWithNoTests --coverage --run", + "test:watch": "vitest --passWithNoTests --coverage", + "all": "BUILD_REASON='publish' turbo run all_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "bench": "ts-node-esm src/bench.ts", + "build": "turbo run build-lib_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "build-lib_": "vite build", + "format": "turbo run format_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-01", + "format_": "prettier --cache-location .cache/prettier --plugin prettier-plugin-svelte --plugin prettier-plugin-tailwindcss --write .", + "p1": "RUN=1 NODE_NO_WARNINGS=1 ts-node-esm src/p1.ts", + "p2": "RUN=1 NODE_NO_WARNINGS=1 ts-node-esm src/p2.ts" + }, + "exports": { + "./bench": { + "types": "./src/bench.ts", + "import": "./dist/bench.js", + "default": "./dist/bench.js" + }, + "./p1": { + "types": "./src/p1.ts", + "import": "./dist/p1.js", + "default": "./dist/p1.js" + }, + "./p2": { + "types": "./src/p2.ts", + "import": "./dist/p2.js", + "default": "./dist/p2.js" + }, + "./readme": "./readme.md" + }, + "dependencies": { + "@alexaegis/advent-of-code-lib": "workspace:^" + }, + "devDependencies": { + "@alexaegis/eslint-config-vitest": "^0.9.1", + "@alexaegis/ts": "^0.9.1", + "@alexaegis/vite": "^0.9.1", + "@alexaegis/vitest": "^0.9.1", + "@types/node": "^20.10.1", + "benny": "^3.7.1", + "vite": "^5.0.4", + "vitest": "^0.34.6" + } +} diff --git a/solutions/typescript/2023/01/readme.md b/solutions/typescript/2023/01/readme.md new file mode 100644 index 000000000..90ad43ee0 --- /dev/null +++ b/solutions/typescript/2023/01/readme.md @@ -0,0 +1,9 @@ +# [Day 1: -](https://adventofcode.com/2023/day/1) + +## [Part One](https://adventofcode.com/2023/day/1#part1) + +> [TypeScript](/solutions/typescript/2023/01/src/p1.ts) + +## [Part Two](https://adventofcode.com/2023/day/1#part2) + +> [TypeScript](/solutions/typescript/2023/01/src/p2.ts) diff --git a/solutions/typescript/2023/01/src/bench.ts b/solutions/typescript/2023/01/src/bench.ts new file mode 100644 index 000000000..08b9426b5 --- /dev/null +++ b/solutions/typescript/2023/01/src/bench.ts @@ -0,0 +1,18 @@ +import { loadTaskResources } from '@alexaegis/advent-of-code-lib'; +import { defaultBench } from '@alexaegis/advent-of-code-lib/benchmark'; +import { add } from 'benny'; +import packageJson from '../package.json'; +import { p1 } from './p1.js'; +import { p2 } from './p2.js'; + +await defaultBench( + '2023 - Day 1', + add('Part One', async () => { + const { input } = await loadTaskResources(packageJson.aoc); + return () => p1(input); + }), + add('Part Two', async () => { + const { input } = await loadTaskResources(packageJson.aoc); + return () => p2(input); + }), +); diff --git a/solutions/typescript/2023/01/src/p1.spec.ts b/solutions/typescript/2023/01/src/p1.spec.ts new file mode 100644 index 000000000..35710bf53 --- /dev/null +++ b/solutions/typescript/2023/01/src/p1.spec.ts @@ -0,0 +1,20 @@ +import { loadTaskResources } from '@alexaegis/advent-of-code-lib'; +import { describe, expect, it } from 'vitest'; +import packageJson from '../package.json'; +import { p1 } from './p1.js'; + +describe('2023 01 p1', () => { + describe('the input', () => { + it('should solve the input', async () => { + const resources = await loadTaskResources(packageJson.aoc); + expect(p1(resources.input)).to.equal(0); + }); + }); + + describe('example 1', () => { + it('should be solved', async () => { + const resources = await loadTaskResources(packageJson.aoc, 'example.1.txt'); + expect(p1(resources.input)).to.equal(0); + }); + }); +}); diff --git a/solutions/typescript/2023/01/src/p1.ts b/solutions/typescript/2023/01/src/p1.ts new file mode 100644 index 000000000..61a144160 --- /dev/null +++ b/solutions/typescript/2023/01/src/p1.ts @@ -0,0 +1,10 @@ +import { DOUBLE_NEWLINE, task } from '@alexaegis/advent-of-code-lib'; +import packageJson from '../package.json'; + +export const p1 = (input: string): number => + input + .split(DOUBLE_NEWLINE) + .map((group) => group.splitToInt().sum()) + .max(); + +await task(p1, packageJson.aoc); // ? ~?ms diff --git a/solutions/typescript/2023/01/src/p2.spec.ts b/solutions/typescript/2023/01/src/p2.spec.ts new file mode 100644 index 000000000..171e9bbf9 --- /dev/null +++ b/solutions/typescript/2023/01/src/p2.spec.ts @@ -0,0 +1,20 @@ +import { loadTaskResources } from '@alexaegis/advent-of-code-lib'; +import { describe, expect, it } from 'vitest'; +import packageJson from '../package.json'; +import { p2 } from './p2.js'; + +describe('2023 01 p2', () => { + describe('the input', () => { + it('should solve the input', async () => { + const { input } = await loadTaskResources(packageJson.aoc); + expect(p2(input)).to.equal(199_357); + }); + }); + + describe('example 1', () => { + it('should be solved', async () => { + const { input } = await loadTaskResources(packageJson.aoc, 'example.1.txt'); + expect(p2(input)).to.equal(45_000); + }); + }); +}); diff --git a/solutions/typescript/2023/01/src/p2.ts b/solutions/typescript/2023/01/src/p2.ts new file mode 100644 index 000000000..2c248e149 --- /dev/null +++ b/solutions/typescript/2023/01/src/p2.ts @@ -0,0 +1,10 @@ +import { DOUBLE_NEWLINE, task } from '@alexaegis/advent-of-code-lib'; +import packageJson from '../package.json'; + +export const p2 = (input: string): number => + input + .split(DOUBLE_NEWLINE) + .map((group) => group.splitToInt().sum()) + .max(); + +await task(p2, packageJson.aoc); // ? ~?ms diff --git a/solutions/typescript/2023/01/tsconfig.json b/solutions/typescript/2023/01/tsconfig.json new file mode 100644 index 000000000..14734b74d --- /dev/null +++ b/solutions/typescript/2023/01/tsconfig.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig?mark=managed-by-autotool", + "extends": "@alexaegis/ts/node", + "compilerOptions": { + "rootDir": "../../../../", + "outDir": ".cache/tsc" + }, + "files": ["package.json", "../../../../package.json"], + "include": [ + "src/**/*", + "static/**/*", + "__mocks__/**/*", + "*", + ".*", + "*.json", + ".*.json", + "**/*.json" + ], + "exclude": [ + "node_modules", + "dist", + "coverage", + "typedoc", + ".turbo", + ".cache", + "vite*.config.ts.timestamp-*" + ] +} diff --git a/solutions/typescript/2023/01/typedoc.json b/solutions/typescript/2023/01/typedoc.json new file mode 100644 index 000000000..0f3238ede --- /dev/null +++ b/solutions/typescript/2023/01/typedoc.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://typedoc.org/schema.json?mark=managed-by-autotool", + "extends": ["../../../../.config/typedoc.base.json"], + "entryPoints": ["src/*"] +} diff --git a/solutions/typescript/2023/01/vite.config.ts b/solutions/typescript/2023/01/vite.config.ts new file mode 100644 index 000000000..b6d107cd0 --- /dev/null +++ b/solutions/typescript/2023/01/vite.config.ts @@ -0,0 +1,19 @@ +// managed-by-autotool + +import { pakk } from '@alexaegis/vite'; +import { defineConfig } from 'vite'; + +export default defineConfig({ + build: { + target: 'es2022', + lib: { + entry: [], + formats: ['es'], + }, + }, + plugins: [ + pakk({ + dts: false, + }), + ], +}); diff --git a/solutions/typescript/2023/01/vitest.config.ts b/solutions/typescript/2023/01/vitest.config.ts new file mode 100644 index 000000000..d82b44605 --- /dev/null +++ b/solutions/typescript/2023/01/vitest.config.ts @@ -0,0 +1,3 @@ +// managed-by-autotool + +export { vitestNodeConfig as default } from '@alexaegis/vitest'; diff --git a/solutions/typescript/libs/lib/src/platform/bench-task.function.ts b/solutions/typescript/libs/lib/src/platform/bench-task.function.ts index c9b934c30..30c00e4f0 100644 --- a/solutions/typescript/libs/lib/src/platform/bench-task.function.ts +++ b/solutions/typescript/libs/lib/src/platform/bench-task.function.ts @@ -15,12 +15,16 @@ export const benchTask = async ( resources: TaskResources, logger?: Logger, ): Promise => { - const obs = new PerformanceObserver((list) => { - list.getEntries().forEach((entry) => { - logger?.(`${entry.name}: ${roundToDecimal(entry.duration, 2)} ms`); + // TODO: Remove the if once PerformanceObserver is implemented in bun + if (process.versions['bun'] === undefined) { + const obs = new PerformanceObserver((list) => { + list.getEntries().forEach((entry) => { + logger?.(`${entry.name}: ${roundToDecimal(entry.duration, 2)} ms`); + }); }); - }); - obs.observe({ entryTypes: ['measure'], buffered: true }); + obs.observe({ entryTypes: ['measure'], buffered: true }); + } + performance.mark('runstart'); const result = await runner(resources.input, resources.args); performance.mark('runend'); diff --git a/solutions/typescript/readme.md b/solutions/typescript/readme.md index a05eefff7..547f74d1c 100644 --- a/solutions/typescript/readme.md +++ b/solutions/typescript/readme.md @@ -1,5 +1,41 @@ # Advent of Code TypeScript Solutions +## [2023](https://adventofcode.com/2023/) + +[![2023 TypeScript Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/typescript/2023.json)](/solutions/typescript/2023/) + + + +| Day | Part One | Part Two | +| --------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | +| [Day 1](/solutions/typescript/2023/01/) | [?ms](/solutions/typescript/2023/01/src/p1.ts) | [?ms](/solutions/typescript/2023/01/src/p2.ts) | +| Day 2 | - | - | +| Day 3 | - | - | +| Day 4 | - | - | +| Day 5 | - | - | +| Day 6 | - | - | +| Day 7 | - | - | +| Day 8 | - | - | +| Day 9 | - | - | +| Day 10 | - | - | +| Day 11 | - | - | +| Day 12 | - | - | +| Day 13 | - | - | +| Day 14 | - | - | +| Day 15 | - | - | +| Day 16 | - | - | +| Day 17 | - | - | +| Day 18 | - | - | +| Day 19 | - | - | +| Day 20 | - | - | +| Day 21 | - | - | +| Day 22 | - | - | +| Day 23 | - | - | +| Day 24 | - | - | +| Day 25 | - | - | + + + ## [2022](https://adventofcode.com/2022/) [![2022 TypeScript Progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AlexAegis/advent-of-code/master/.github/badges/typescript/2022.json)](/solutions/typescript/2022/)