mirror of
https://github.com/seigler/aoc2021
synced 2025-07-27 01:16:09 +00:00
day 1
This commit is contained in:
parent
76fe338201
commit
c2dfb1d245
4 changed files with 81 additions and 14 deletions
|
@ -5,16 +5,20 @@
|
||||||
"days": [
|
"days": [
|
||||||
{
|
{
|
||||||
"part1": {
|
"part1": {
|
||||||
"solved": false,
|
"solved": true,
|
||||||
"result": null,
|
"result": "1288",
|
||||||
"attempts": [],
|
"attempts": [
|
||||||
"time": null
|
"1420"
|
||||||
|
],
|
||||||
|
"time": 0.24
|
||||||
},
|
},
|
||||||
"part2": {
|
"part2": {
|
||||||
"solved": false,
|
"solved": true,
|
||||||
"result": null,
|
"result": "1311",
|
||||||
"attempts": [],
|
"attempts": [
|
||||||
"time": null
|
"1248"
|
||||||
|
],
|
||||||
|
"time": 0.55
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
12
README.md
12
README.md
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<!--SOLUTIONS-->
|
<!--SOLUTIONS-->
|
||||||
|
|
||||||

|
[](src/day01)
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
@ -69,9 +69,9 @@ npm start 1
|
||||||
|
|
||||||
```
|
```
|
||||||
Day 01
|
Day 01
|
||||||
Time part 1: -
|
Time part 1: 0.24ms
|
||||||
Time part 2: -
|
Time part 2: 0.55ms
|
||||||
Both parts: -
|
Both parts: 0.79ms
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -243,8 +243,8 @@ Both parts: -
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
Total stars: 0/50
|
Total stars: 2/50
|
||||||
Total time: 0ms
|
Total time: 0.79ms
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--/RESULTS-->
|
<!--/RESULTS-->
|
||||||
|
|
9
src/day01/README.md
Normal file
9
src/day01/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# 🎄 Advent of Code 2021 - day 1 🎄
|
||||||
|
|
||||||
|
## Info
|
||||||
|
|
||||||
|
Task description: [link](https://adventofcode.com/2021/day/1)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
...
|
54
src/day01/index.js
Normal file
54
src/day01/index.js
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import run from "aocrunner"
|
||||||
|
|
||||||
|
const parseInput = (rawInput) => rawInput.split('\n').map(Number)
|
||||||
|
|
||||||
|
const part1 = (rawInput) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
return input.reduce((acc, current, index) => acc + (current > input[index-1] ? 1 : 0), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
const part2 = (rawInput) => {
|
||||||
|
const input = parseInput(rawInput)
|
||||||
|
let increases = 0
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
if (i > 2 && input[i] > input[i-3]) {
|
||||||
|
increases++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return increases
|
||||||
|
}
|
||||||
|
|
||||||
|
run({
|
||||||
|
part1: {
|
||||||
|
tests: [
|
||||||
|
{ input: `199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263`, expected: 7 },
|
||||||
|
],
|
||||||
|
solution: part1,
|
||||||
|
},
|
||||||
|
part2: {
|
||||||
|
tests: [
|
||||||
|
{ input: `199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263`, expected: 5 },
|
||||||
|
],
|
||||||
|
solution: part2,
|
||||||
|
},
|
||||||
|
trimTestInputs: true,
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue