Skip to content

Commit

Permalink
chore: prepare 2023 day 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAegis committed Dec 2, 2023
1 parent a72e085 commit 60b4fe2
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 1 deletion.
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions resources/2023/01/example.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
Empty file added resources/2023/02/example.1.txt
Empty file.
Empty file added resources/2023/02/input.txt
Empty file.
2 changes: 1 addition & 1 deletion solutions/typescript/2015/01/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig?mark=managed-by-autotool",
"extends": "./node_modules/@alexaegis/ts/node.json",
"extends": "@alexaegis/ts/node",
"compilerOptions": {
"rootDir": "../../../../",
"outDir": ".cache/tsc"
Expand Down
13 changes: 13 additions & 0 deletions solutions/typescript/2023/02/.eslintignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions solutions/typescript/2023/02/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// managed-by-autotool

/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['../../../../.eslintrc.cjs', '@alexaegis/eslint-config-vitest'],
};
38 changes: 38 additions & 0 deletions solutions/typescript/2023/02/.prettierignore
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions solutions/typescript/2023/02/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "@alexaegis/advent-of-code-2023-02",
"description": "Advent of Code 2023 02 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": 2,
"year": 2023
},
"scripts": {
"lint:depcheck": "turbo run lint:depcheck_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-02",
"lint:depcheck_": "depcheck",
"lint:es": "turbo run lint:es_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-02",
"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-02",
"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-02",
"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-02",
"lint:tsc_": "tsc --noEmit",
"test": "turbo run test_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-02",
"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-02",
"bench": "ts-node-esm src/bench.ts",
"build": "turbo run build-lib_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-02",
"build-lib_": "vite build",
"format": "turbo run format_ --concurrency 16 --cache-dir .cache/turbo --filter @alexaegis/advent-of-code-2023-02",
"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"
}
}
9 changes: 9 additions & 0 deletions solutions/typescript/2023/02/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# [Day 2: -](https://adventofcode.com/2023/day/2)

## [Part One](https://adventofcode.com/2023/day/2#part1)

> [TypeScript](/solutions/typescript/2023/02/src/p1.ts)
## [Part Two](https://adventofcode.com/2023/day/2#part2)

> [TypeScript](/solutions/typescript/2023/02/src/p2.ts)
18 changes: 18 additions & 0 deletions solutions/typescript/2023/02/src/bench.ts
Original file line number Diff line number Diff line change
@@ -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 2',
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);
}),
);
20 changes: 20 additions & 0 deletions solutions/typescript/2023/02/src/p1.spec.ts
Original file line number Diff line number Diff line change
@@ -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 02 p1', () => {
describe('the input', () => {
it('should solve the input', async () => {
const resources = await loadTaskResources(packageJson.aoc);
expect(p1(resources.input)).toEqual(0);
});
});

describe('example 1', () => {
it('should be solved', async () => {
const resources = await loadTaskResources(packageJson.aoc, 'example.1.txt');
expect(p1(resources.input)).toEqual(0);
});
});
});
23 changes: 23 additions & 0 deletions solutions/typescript/2023/02/src/p1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NEWLINE, task } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json';

export const p1 = (input: string): number => {
return input
.split(NEWLINE)
.map((group) => {
const f = group
.chars()
.find((l) => /\d/.test(l))
?.toInt()
.toString();
const l = group
.chars()
.reverse()
.find((l) => /\d/.test(l))
?.toInt()
.toString();
return f && l ? (f + l).toInt() : 0;
})
.sum();
};
await task(p1, packageJson.aoc); // 54644 ~?ms
20 changes: 20 additions & 0 deletions solutions/typescript/2023/02/src/p2.spec.ts
Original file line number Diff line number Diff line change
@@ -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 02 p2', () => {
describe('the input', () => {
it('should solve the input', async () => {
const { input } = await loadTaskResources(packageJson.aoc);
expect(p2(input)).toEqual(0);
});
});

describe('example 1', () => {
it('should be solved', async () => {
const { input } = await loadTaskResources(packageJson.aoc, 'example.1.txt');
expect(p2(input)).toEqual(0);
});
});
});
58 changes: 58 additions & 0 deletions solutions/typescript/2023/02/src/p2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { NEWLINE, task } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json';

export const p2 = (input: string): number => {
return input
.split(NEWLINE)
.map((line) => {
let bufferForFirst = '';
for (const l of line.chars()) {
bufferForFirst += l;
bufferForFirst = bufferForFirst
.replaceAll('one', '1')
.replaceAll('two', '2')
.replaceAll('three', '3')
.replaceAll('four', '4')
.replaceAll('five', '5')
.replaceAll('six', '6')
.replaceAll('seven', '7')
.replaceAll('eight', '8')

.replaceAll('nine', '9');
}

let bufferForLast = '';
for (const l of line.chars().reverse()) {
bufferForLast = l + bufferForLast;
bufferForLast = bufferForLast
.replaceAll('one', '1')
.replaceAll('two', '2')
.replaceAll('three', '3')
.replaceAll('four', '4')
.replaceAll('five', '5')
.replaceAll('six', '6')
.replaceAll('seven', '7')
.replaceAll('eight', '8')

.replaceAll('nine', '9');
}

const f = bufferForFirst
.chars()
.find((l) => /\d/.test(l))
?.toInt()
.toString();

const l = bufferForLast
.chars()
.reverse()
.find((l) => /\d/.test(l))
?.toInt()
.toString();

return f && l ? (f + l).toInt() : 0;
})
.sum();
};

await task(p2, packageJson.aoc); // 53348 ~?ms
28 changes: 28 additions & 0 deletions solutions/typescript/2023/02/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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-*"
]
}
5 changes: 5 additions & 0 deletions solutions/typescript/2023/02/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://typedoc.org/schema.json?mark=managed-by-autotool",
"extends": ["../../../../.config/typedoc.base.json"],
"entryPoints": ["src/*"]
}
Loading

0 comments on commit 60b4fe2

Please sign in to comment.