This commit is contained in:
Joshua Seigler 2021-12-01 15:20:40 -05:00
parent 76fe338201
commit c2dfb1d245
4 changed files with 81 additions and 14 deletions

View file

@ -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
} }
}, },
{ {

View file

@ -11,7 +11,7 @@
<!--SOLUTIONS--> <!--SOLUTIONS-->
![Day](https://badgen.net/badge/01/%E2%98%86%E2%98%86/gray) [![Day](https://badgen.net/badge/01/%E2%98%85%E2%98%85/green)](src/day01)
![Day](https://badgen.net/badge/02/%E2%98%86%E2%98%86/gray) ![Day](https://badgen.net/badge/02/%E2%98%86%E2%98%86/gray)
![Day](https://badgen.net/badge/03/%E2%98%86%E2%98%86/gray) ![Day](https://badgen.net/badge/03/%E2%98%86%E2%98%86/gray)
![Day](https://badgen.net/badge/04/%E2%98%86%E2%98%86/gray) ![Day](https://badgen.net/badge/04/%E2%98%86%E2%98%86/gray)
@ -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
View 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
View 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,
})