This commit is contained in:
Joshua Seigler 2024-12-05 09:59:21 -05:00
parent a71ae9c4d7
commit a9a646b1e1
No known key found for this signature in database
4 changed files with 112 additions and 8 deletions

View file

@ -33,10 +33,10 @@
},
{
"part1": {
"solved": false,
"result": null,
"solved": true,
"result": "539590",
"attempts": [],
"time": null
"time": 2.532209
},
"part2": {
"solved": false,

View file

@ -13,7 +13,7 @@
[![Day](https://badgen.net/badge/01/%E2%98%85%E2%98%85/green)](src/day01)
[![Day](https://badgen.net/badge/02/%E2%98%85%E2%98%85/green)](src/day02)
![Day](https://badgen.net/badge/03/%E2%98%86%E2%98%86/gray)
[![Day](https://badgen.net/badge/03/%E2%98%85%E2%98%86/yellow)](src/day03)
![Day](https://badgen.net/badge/04/%E2%98%86%E2%98%86/gray)
![Day](https://badgen.net/badge/05/%E2%98%86%E2%98%86/gray)
![Day](https://badgen.net/badge/06/%E2%98%86%E2%98%86/gray)
@ -83,9 +83,9 @@ Both parts: 1.293ms
```
Day 03
Time part 1: -
Time part 1: 2.529ms
Time part 2: -
Both parts: -
Both parts: 2.529ms
```
```
@ -243,8 +243,8 @@ Both parts: -
```
```
Total stars: 4/50
Total time: 3.173ms
Total stars: 5/50
Total time: 5.703ms
```
<!--/RESULTS-->

9
src/day03/README.md Normal file
View file

@ -0,0 +1,9 @@
# 🎄 Advent of Code 2023 - day 3 🎄
## Info
Task description: [link](https://adventofcode.com/2023/day/3)
## Notes
...

95
src/day03/index.ts Normal file
View file

@ -0,0 +1,95 @@
import run from "aocrunner"
const parseInput = (rawInput: string) => rawInput.split("\n")
const part1 = (rawInput: string) => {
const input = parseInput(rawInput)
let total = 0
input.forEach((line, row) => {
let numString = ""
line.split("").forEach((char, col) => {
if (/\d/.test(char)) {
numString += char
}
if (!/\d/.test(line[col + 1] ?? "")) {
// time to test current string
if (numString === "") {
return
}
for (
let r = Math.max(row - 1, 0);
r <= Math.min(row + 1, input.length - 1);
r++
) {
for (
let c = Math.max(col - numString.length, 0);
c <= Math.min(col + 1, line.length - 1);
c++
) {
if (!/\d|\./.test(input[r].charAt(c))) {
total += parseInt(numString)
numString = ""
return // done with this char
}
}
}
numString = ""
}
})
})
return total
}
const part2 = (rawInput: string) => {
const input = parseInput(rawInput)
input.forEach((line, row) => {
line.split("").forEach((char, col) => {
if (char === "*") {
// ask every found number if it touches a star
// add to total the product of all the pairs
}
})
})
return
}
run({
part1: {
tests: [
{
input: `467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..`,
expected: 4361,
},
],
solution: part1,
},
part2: {
tests: [
{
input: `467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..`,
expected: 467835,
},
],
solution: part2,
},
trimTestInputs: true,
onlyTests: false,
})