mirror of
https://github.com/seigler/aoc2022
synced 2025-07-26 06:26:09 +00:00
I should probably check this in at some point huh
This commit is contained in:
commit
23e19496a1
20 changed files with 3507 additions and 0 deletions
357
.aocrunner.json
Normal file
357
.aocrunner.json
Normal file
|
@ -0,0 +1,357 @@
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"year": 2022,
|
||||||
|
"language": "ts",
|
||||||
|
"days": [
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "75501",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 0.482244
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "215594",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 0.499996
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "14069",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 2.829329
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "12411",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 2.050315
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "7674",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 0.867237
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "2805",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 1.129849
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "509",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 2.801134
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "870",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 2.434697
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "FWSHSPJWM",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 1.861013
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": true,
|
||||||
|
"result": "PWPWHGFZS",
|
||||||
|
"attempts": [],
|
||||||
|
"time": 1.414494
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"part1": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
},
|
||||||
|
"part2": {
|
||||||
|
"solved": false,
|
||||||
|
"result": null,
|
||||||
|
"attempts": [],
|
||||||
|
"time": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
node_modules
|
||||||
|
*.temp.*
|
||||||
|
*/**/*.temp.*
|
||||||
|
*/**/input.txt
|
||||||
|
*.log
|
||||||
|
*/**/*.log
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
.env
|
||||||
|
dist
|
1
.prettierignore
Normal file
1
.prettierignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
lib
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"arrowParens": "always",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"printWidth": 80,
|
||||||
|
"proseWrap": "preserve",
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": false,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
254
README.md
Normal file
254
README.md
Normal file
|
@ -0,0 +1,254 @@
|
||||||
|
<!-- Entries between SOLUTIONS and RESULTS tags are auto-generated -->
|
||||||
|
|
||||||
|
[](https://adventofcode.com/2022)
|
||||||
|
[](https://nodejs.org/en/download/)
|
||||||
|

|
||||||
|
[](https://github.com/caderek/aocrunner)
|
||||||
|
|
||||||
|
# 🎄 Advent of Code 2022 🎄
|
||||||
|
|
||||||
|
## Solutions
|
||||||
|
|
||||||
|
<!--SOLUTIONS-->
|
||||||
|
|
||||||
|
[](src/day01)
|
||||||
|
[](src/day02)
|
||||||
|
[](src/day03)
|
||||||
|
[](src/day04)
|
||||||
|
[](src/day05)
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
<!--/SOLUTIONS-->
|
||||||
|
|
||||||
|
_Click a badge to go to the specific day._
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
npm i
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running in dev mode
|
||||||
|
|
||||||
|
```
|
||||||
|
npm start <day>
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm start 1
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Results
|
||||||
|
|
||||||
|
<!--RESULTS-->
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 01
|
||||||
|
Time part 1: 0.482ms
|
||||||
|
Time part 2: 0.5ms
|
||||||
|
Both parts: 0.98224ms
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 02
|
||||||
|
Time part 1: 2.829ms
|
||||||
|
Time part 2: 2.05ms
|
||||||
|
Both parts: 4.879644ms
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 03
|
||||||
|
Time part 1: 0.867ms
|
||||||
|
Time part 2: 1.13ms
|
||||||
|
Both parts: 1.9970860000000001ms
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 04
|
||||||
|
Time part 1: 2.801ms
|
||||||
|
Time part 2: 2.435ms
|
||||||
|
Both parts: 5.235830999999999ms
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 05
|
||||||
|
Time part 1: 1.861ms
|
||||||
|
Time part 2: 1.414ms
|
||||||
|
Both parts: 3.275507ms
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 06
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 07
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 08
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 09
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 10
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 11
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 12
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 13
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 14
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 15
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 16
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 17
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 18
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 19
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 20
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 21
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 22
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 23
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 24
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Day 25
|
||||||
|
Time part 1: -
|
||||||
|
Time part 2: -
|
||||||
|
Both parts: -
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Total stars: 10/50
|
||||||
|
Total time: 16.37ms
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--/RESULTS-->
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
✨🎄🎁🎄🎅🎄🎁🎄✨
|
2302
package-lock.json
generated
Normal file
2302
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
25
package.json
Normal file
25
package.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"name": "aoc2022",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Advent of Code 2022 - solutions",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "aocrunner day",
|
||||||
|
"build": "aocrunner build",
|
||||||
|
"format": "prettier -w src"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"aoc"
|
||||||
|
],
|
||||||
|
"author": "Joshua Seigler",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^16.11.6",
|
||||||
|
"aocrunner": "^1.6.1",
|
||||||
|
"prettier": "^2.4.1"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.13.0"
|
||||||
|
}
|
||||||
|
}
|
9
src/day01/README.md
Normal file
9
src/day01/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# 🎄 Advent of Code 2022 - day 1 🎄
|
||||||
|
|
||||||
|
## Info
|
||||||
|
|
||||||
|
Task description: [link](https://adventofcode.com/2022/day/1)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
...
|
69
src/day01/index.ts
Normal file
69
src/day01/index.ts
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
|
||||||
|
const parseInput = (rawInput: string) => {
|
||||||
|
const byElf = rawInput.split('\n\n')
|
||||||
|
return byElf.map(x => x.split('\n').map(x => +x))
|
||||||
|
}
|
||||||
|
|
||||||
|
const part1 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
const totals = input.map(elf => elf.reduce((acc, cur) => acc + cur))
|
||||||
|
const max = totals.sort((a,b) => b - a)[0]
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
const totals = input.map(elf => elf.reduce((acc, cur) => acc + cur))
|
||||||
|
const sorted = totals.sort((a,b) => b - a)
|
||||||
|
return sorted[0] + sorted[1] + sorted[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `1000
|
||||||
|
2000
|
||||||
|
3000
|
||||||
|
|
||||||
|
4000
|
||||||
|
|
||||||
|
5000
|
||||||
|
6000
|
||||||
|
|
||||||
|
7000
|
||||||
|
8000
|
||||||
|
9000
|
||||||
|
|
||||||
|
10000`,
|
||||||
|
expected: 24000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `1000
|
||||||
|
2000
|
||||||
|
3000
|
||||||
|
|
||||||
|
4000
|
||||||
|
|
||||||
|
5000
|
||||||
|
6000
|
||||||
|
|
||||||
|
7000
|
||||||
|
8000
|
||||||
|
9000
|
||||||
|
|
||||||
|
10000`,
|
||||||
|
expected: 45000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: true,
|
||||||
|
onlyTests: false,
|
||||||
|
})
|
9
src/day02/README.md
Normal file
9
src/day02/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# 🎄 Advent of Code 2022 - day 2 🎄
|
||||||
|
|
||||||
|
## Info
|
||||||
|
|
||||||
|
Task description: [link](https://adventofcode.com/2022/day/2)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
...
|
111
src/day02/index.ts
Normal file
111
src/day02/index.ts
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
|
||||||
|
const parseInput = (rawInput: string) =>
|
||||||
|
rawInput
|
||||||
|
.trim()
|
||||||
|
.split("\n")
|
||||||
|
.map((x) => x.split(" "))
|
||||||
|
|
||||||
|
const shapeScores = {
|
||||||
|
X: 1,
|
||||||
|
Y: 2,
|
||||||
|
Z: 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
const outcomeScores = {
|
||||||
|
LOSS: 0,
|
||||||
|
DRAW: 3,
|
||||||
|
WIN: 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
type gameType = ["A" | "B" | "C", "X" | "Y" | "Z"]
|
||||||
|
const cycle = {
|
||||||
|
A: {
|
||||||
|
X: "DRAW" as const,
|
||||||
|
Y: "WIN" as const,
|
||||||
|
Z: "LOSS" as const,
|
||||||
|
},
|
||||||
|
B: {
|
||||||
|
X: "LOSS" as const,
|
||||||
|
Y: "DRAW" as const,
|
||||||
|
Z: "WIN" as const,
|
||||||
|
},
|
||||||
|
C: {
|
||||||
|
X: "WIN" as const,
|
||||||
|
Y: "LOSS" as const,
|
||||||
|
Z: "DRAW" as const,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
function getOutcome([them, us]: gameType): keyof typeof outcomeScores {
|
||||||
|
return cycle[them][us]
|
||||||
|
}
|
||||||
|
|
||||||
|
const part1 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput) as gameType[]
|
||||||
|
let score = 0
|
||||||
|
for (const [them, us] of input) {
|
||||||
|
score += shapeScores[us]
|
||||||
|
score += outcomeScores[getOutcome([them, us])]
|
||||||
|
}
|
||||||
|
return score
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput) as gameType[]
|
||||||
|
let score = 0
|
||||||
|
const outcomes = {
|
||||||
|
X: "LOSS" as const,
|
||||||
|
Y: "DRAW" as const,
|
||||||
|
Z: "WIN" as const,
|
||||||
|
}
|
||||||
|
const key = {
|
||||||
|
A: {
|
||||||
|
DRAW: "X" as const,
|
||||||
|
WIN: "Y" as const,
|
||||||
|
LOSS: "Z" as const,
|
||||||
|
},
|
||||||
|
B: {
|
||||||
|
LOSS: "X" as const,
|
||||||
|
DRAW: "Y" as const,
|
||||||
|
WIN: "Z" as const,
|
||||||
|
},
|
||||||
|
C: {
|
||||||
|
WIN: "X" as const,
|
||||||
|
LOSS: "Y" as const,
|
||||||
|
DRAW: "Z" as const,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [them, outcome] of input) {
|
||||||
|
score += outcomeScores[outcomes[outcome]]
|
||||||
|
score += shapeScores[key[them][outcomes[outcome]]]
|
||||||
|
}
|
||||||
|
return score
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `A Y
|
||||||
|
B X
|
||||||
|
C Z`,
|
||||||
|
expected: 15,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `A Y
|
||||||
|
B X
|
||||||
|
C Z`,
|
||||||
|
expected: 12,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: true,
|
||||||
|
onlyTests: false,
|
||||||
|
})
|
9
src/day03/README.md
Normal file
9
src/day03/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# 🎄 Advent of Code 2022 - day 3 🎄
|
||||||
|
|
||||||
|
## Info
|
||||||
|
|
||||||
|
Task description: [link](https://adventofcode.com/2022/day/3)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
...
|
78
src/day03/index.ts
Normal file
78
src/day03/index.ts
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
import { assert } from "console"
|
||||||
|
|
||||||
|
const parseInput = (rawInput: string) => rawInput.trim().split("\n")
|
||||||
|
|
||||||
|
function getPriority(c: string) {
|
||||||
|
const code = c.charCodeAt(0)
|
||||||
|
if (code >= 97) {
|
||||||
|
// "a"
|
||||||
|
return code - 96
|
||||||
|
}
|
||||||
|
return code - 65 /* "A" */ + 27
|
||||||
|
}
|
||||||
|
|
||||||
|
const part1 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
let total = 0
|
||||||
|
for (const rucksack of input) {
|
||||||
|
const [left, right] = [
|
||||||
|
rucksack.slice(0, rucksack.length / 2),
|
||||||
|
rucksack.slice(rucksack.length / 2),
|
||||||
|
]
|
||||||
|
const leftItems = new Set(left.split(""))
|
||||||
|
const common = [...leftItems.values()].filter((c) => right.includes(c))
|
||||||
|
total += getPriority(common[0])
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
let total = 0
|
||||||
|
const groupSize = 3
|
||||||
|
for (let g = 0; g < input.length; g += groupSize) {
|
||||||
|
const items = new Set(input[g])
|
||||||
|
for (let m = 1; m < groupSize; m++) {
|
||||||
|
for (const i of [...items.values()]) {
|
||||||
|
if (input[g + m].includes(i)) continue
|
||||||
|
else items.delete(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total += getPriority([...items.values()][0])
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `vJrwpWtwJgWrhcsFMMfFFhFp
|
||||||
|
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||||
|
PmmdzqPrVvPwwTWBwg
|
||||||
|
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||||
|
ttgJtRGJQctTZtZT
|
||||||
|
CrZsJsPPZsGzwwsLwLmpwMDw`,
|
||||||
|
expected: 157,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `vJrwpWtwJgWrhcsFMMfFFhFp
|
||||||
|
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||||
|
PmmdzqPrVvPwwTWBwg
|
||||||
|
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||||
|
ttgJtRGJQctTZtZT
|
||||||
|
CrZsJsPPZsGzwwsLwLmpwMDw`,
|
||||||
|
expected: 70,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: true,
|
||||||
|
onlyTests: false,
|
||||||
|
})
|
9
src/day04/README.md
Normal file
9
src/day04/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# 🎄 Advent of Code 2022 - day 4 🎄
|
||||||
|
|
||||||
|
## Info
|
||||||
|
|
||||||
|
Task description: [link](https://adventofcode.com/2022/day/4)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
...
|
66
src/day04/index.ts
Normal file
66
src/day04/index.ts
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
|
||||||
|
const parseInput = (rawInput: string) =>
|
||||||
|
rawInput
|
||||||
|
.trim()
|
||||||
|
.split("\n")
|
||||||
|
.map((l) => l.split(",").map((r) => r.split("-").map((n) => +n)))
|
||||||
|
|
||||||
|
const part1 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
let fullSubsets = 0
|
||||||
|
for (const [a, b] of input) {
|
||||||
|
const [lower, higher] =
|
||||||
|
a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]) ? [a, b] : [b, a]
|
||||||
|
if (lower[1] >= higher[1]) {
|
||||||
|
fullSubsets += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fullSubsets
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
let partialSubsets = 0
|
||||||
|
for (const [a, b] of input) {
|
||||||
|
const [lower, higher] =
|
||||||
|
a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]) ? [a, b] : [b, a]
|
||||||
|
if (higher[0] <= lower[1]) {
|
||||||
|
partialSubsets += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return partialSubsets
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8`,
|
||||||
|
expected: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: `2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8`,
|
||||||
|
expected: 4,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: true,
|
||||||
|
onlyTests: false,
|
||||||
|
})
|
9
src/day05/README.md
Normal file
9
src/day05/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# 🎄 Advent of Code 2022 - day 5 🎄
|
||||||
|
|
||||||
|
## Info
|
||||||
|
|
||||||
|
Task description: [link](https://adventofcode.com/2022/day/5)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
...
|
86
src/day05/index.ts
Normal file
86
src/day05/index.ts
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
|
||||||
|
const parseInput = (rawInput: string) => {
|
||||||
|
const [rawState, rawInstructions] = rawInput
|
||||||
|
.split("\n\n")
|
||||||
|
.map((x) => x.split("\n"))
|
||||||
|
const stackCount = (rawState.at(-1)!.length + 1) / 4
|
||||||
|
const state = new Array<string[]>(stackCount)
|
||||||
|
for (let i = 0; i < stackCount; i++) {
|
||||||
|
state[i] = new Array<string>()
|
||||||
|
}
|
||||||
|
for (const line of rawState) {
|
||||||
|
;[...line.matchAll(/[\[ ]([A-Z ])[\] ] ?/g)].forEach(
|
||||||
|
([_match, id], index) => {
|
||||||
|
if (id !== " ") {
|
||||||
|
state[index].unshift(id)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const instructions = rawInstructions.map((x) =>
|
||||||
|
[...x.matchAll(/\d+/g)].map(([num]) => +num),
|
||||||
|
)
|
||||||
|
return { state, instructions }
|
||||||
|
}
|
||||||
|
|
||||||
|
const part1 = (rawInput: string) => {
|
||||||
|
const { state, instructions } = parseInput(rawInput)
|
||||||
|
for (const instruction of instructions) {
|
||||||
|
const [quantity, from, to] = instruction
|
||||||
|
for (let i = 0; i < quantity; i++) {
|
||||||
|
state[to - 1].push(state[from - 1].pop()!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state.map((stack) => stack.at(-1)).join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput: string) => {
|
||||||
|
const { state, instructions } = parseInput(rawInput)
|
||||||
|
for (const instruction of instructions) {
|
||||||
|
const [quantity, from, to] = instruction
|
||||||
|
const moving = state[from - 1].slice(-quantity)
|
||||||
|
state[from - 1].length -= quantity
|
||||||
|
state[to - 1] = state[to - 1].concat(moving)
|
||||||
|
}
|
||||||
|
return state.map((stack) => stack.at(-1)).join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: ` [D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 1 from 1 to 2`,
|
||||||
|
expected: "CMZ",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
input: ` [D]
|
||||||
|
[N] [C]
|
||||||
|
[Z] [M] [P]
|
||||||
|
1 2 3
|
||||||
|
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 1 from 1 to 2`,
|
||||||
|
expected: "MCD",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: false,
|
||||||
|
onlyTests: false,
|
||||||
|
})
|
38
src/template/index.ts
Normal file
38
src/template/index.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
|
||||||
|
const parseInput = (rawInput: string) => rawInput
|
||||||
|
|
||||||
|
const part1 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput: string) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
// {
|
||||||
|
// input: ``,
|
||||||
|
// expected: "",
|
||||||
|
// },
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
// {
|
||||||
|
// input: ``,
|
||||||
|
// expected: "",
|
||||||
|
// },
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: true,
|
||||||
|
onlyTests: false,
|
||||||
|
})
|
31
src/utils/index.ts
Normal file
31
src/utils/index.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* Root for your util libraries.
|
||||||
|
*
|
||||||
|
* You can import them in the src/template/index.ts,
|
||||||
|
* or in the specific file.
|
||||||
|
*
|
||||||
|
* Note that this repo uses ES Modules, so you have to explicitly specify
|
||||||
|
* .js extension (yes, .js not .ts - even for TypeScript files)
|
||||||
|
* for imports that are not imported from node_modules.
|
||||||
|
*
|
||||||
|
* For example:
|
||||||
|
*
|
||||||
|
* correct:
|
||||||
|
*
|
||||||
|
* import _ from 'lodash'
|
||||||
|
* import myLib from '../utils/myLib.js'
|
||||||
|
* import { myUtil } from '../utils/index.js'
|
||||||
|
*
|
||||||
|
* incorrect:
|
||||||
|
*
|
||||||
|
* import _ from 'lodash'
|
||||||
|
* import myLib from '../utils/myLib.ts'
|
||||||
|
* import { myUtil } from '../utils/index.ts'
|
||||||
|
*
|
||||||
|
* also incorrect:
|
||||||
|
*
|
||||||
|
* import _ from 'lodash'
|
||||||
|
* import myLib from '../utils/myLib'
|
||||||
|
* import { myUtil } from '../utils'
|
||||||
|
*
|
||||||
|
*/
|
23
tsconfig.json
Normal file
23
tsconfig.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2020",
|
||||||
|
"module": "es2020",
|
||||||
|
"removeComments": true,
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"preserveConstEnums": true,
|
||||||
|
"strict": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"importHelpers": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"src/**/*.test.ts",
|
||||||
|
"src/**/*.temp.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue