fix scaffolding, start d3

This commit is contained in:
Leonard Lorenz 2025-12-03 10:24:15 +01:00
parent 048cc9d4c2
commit af91eb4ed5
6 changed files with 61 additions and 22 deletions

View file

@ -1,12 +1,13 @@
import { solvables } from "../main.ts";
import type { Solvable } from "../solvable.ts";
import { Day } from "../day.ts";
import { readInput } from "../utils.ts";
class DayOne implements Solvable {
class DayImpl implements Day {
day = 1
input = readInput('01')
public part1(): DayOne {
public part1(): Day {
const vals: [string, number][] = this.input
.split("\n")
.map(line => [line[0], Number.parseInt(line.slice(1))]);
@ -27,7 +28,7 @@ class DayOne implements Solvable {
return this
}
public part2(): DayOne {
public part2(): Day {
const vals: [string, number][] = this.input
.split("\n")
.map(line => [line[0], Number.parseInt(line.slice(1))]);
@ -56,4 +57,4 @@ class DayOne implements Solvable {
}
}
solvables.push(new DayOne())
solvables.push(new DayImpl())

View file

@ -1,6 +1,6 @@
import { solvables } from "../main.ts";
import type { Solvable } from "../solvable.ts";
import type { Day } from "../day.ts";
import { readInput } from "../utils.ts";
const checkWindow = (input: number): boolean => {
@ -16,10 +16,11 @@ const checkWindow = (input: number): boolean => {
return left === right;
}
class DayTwo implements Solvable {
class DayImpl implements Day {
day = 2
input = readInput('02')
public part1(): DayTwo {
public part1(): Day {
const vals: [number, number][] = this.input
.split(",")
.map(range => range.trim().split("-")
@ -31,7 +32,6 @@ class DayTwo implements Solvable {
for (let i = start; i <= end; i++) {
if (String(i).length % 2 === 1) continue
if (checkWindow(i)) {
console.log(i)
invalid.push(i);
}
}
@ -42,9 +42,9 @@ class DayTwo implements Solvable {
return this
}
public part2(): DayTwo {
public part2(): Day {
return this
}
}
solvables.push(new DayTwo())
solvables.push(new DayImpl())

29
solutions/03.ts Normal file
View file

@ -0,0 +1,29 @@
import { solvables } from "../main.ts";
import type { Day } from "../day.ts";
import { readInput } from "../utils.ts";
class DayImpl implements Day {
day = 3
input = readInput('03')
public part1(): Day {
const vals: string[] = this.input
.split("\n")
const result = vals.map(battery => {
const sorted = battery.split("").sort()
return Number.parseInt(sorted[0]) + Number.parseInt(sorted[1])
}).reduce((a, b) => a + b, 0)
console.log(result)
return this
}
public part2(): Day {
return this
}
}
solvables.push(new DayImpl())