mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
2025 day 9 part 1 in TypeScript
This commit is contained in:
39
2025/day09/solve.ts
Executable file
39
2025/day09/solve.ts
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env ts-node
|
||||
import * as fs from 'fs';
|
||||
import { exit } from 'process';
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log("Usage: " + process.argv0 + " " + process.argv[1] + " INPUT_FILE");
|
||||
exit(10);
|
||||
}
|
||||
|
||||
const input_file = fs.readFileSync(process.argv[2], "utf-8");
|
||||
const lines = input_file.trim().split("\n");
|
||||
|
||||
class Point {
|
||||
x: number;
|
||||
y: number;
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
const points = lines.map(line => {
|
||||
const [x, y] = line.split(",");
|
||||
return new Point(+x, +y);
|
||||
});
|
||||
|
||||
let max_size = 0;
|
||||
|
||||
for (let i = 0; i < points.length; ++i) {
|
||||
for (let j = i + 1; j < points.length; ++j) {
|
||||
const width = Math.abs(points[i].x - points[j].x) + 1;
|
||||
const height = Math.abs(points[i].y - points[j].y) + 1;
|
||||
|
||||
max_size = Math.max(max_size, width * height);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Part 1:", max_size);
|
||||
Reference in New Issue
Block a user