28 lines
775 B
TypeScript
28 lines
775 B
TypeScript
|
|
||
|
import { solvables } from "../main.ts";
|
||
|
|
||
|
import type { Solvable } from "../solvable.ts";
|
||
|
import { readInput } from "../utils.ts";
|
||
|
|
||
|
class DayThree implements Solvable {
|
||
|
input = readInput('03')
|
||
|
|
||
|
public part1(): Solvable {
|
||
|
const re = /mul\([0-9]+,[0-9]+\)/g
|
||
|
// get all matches and parse them to int[]
|
||
|
const result = this.input.matchAll(new RegExp(re))
|
||
|
.map(match => match[0]
|
||
|
.slice(4, -1)
|
||
|
.split(',')
|
||
|
.map(arr => Number.parseInt(arr)))
|
||
|
.map(([left, right]) => left * right)
|
||
|
.reduce((prev, curr) => prev + curr)
|
||
|
console.log(result)
|
||
|
return this
|
||
|
}
|
||
|
public part2(): Solvable {
|
||
|
return this
|
||
|
}
|
||
|
}
|
||
|
|
||
|
solvables.push(new DayThree())
|