mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 12:50:32 +01:00
2025 day 9 part 1 in TypeScript
This commit is contained in:
1
2025/day09/.gitignore
vendored
Normal file
1
2025/day09/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
29
2025/day09/package-lock.json
generated
Normal file
29
2025/day09/package-lock.json
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "day09",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.10.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.10.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.2.tgz",
|
||||
"integrity": "sha512-WOhQTZ4G8xZ1tjJTvKOpyEVSGgOTvJAfDK3FNFgELyaTpzhdgHVHeqW8V+UJvzF5BT+/B54T/1S2K6gd9c7bbA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "7.16.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
6
2025/day09/package.json
Normal file
6
2025/day09/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.10.2"
|
||||
}
|
||||
}
|
||||
8
2025/day09/sample.txt
Normal file
8
2025/day09/sample.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
7,1
|
||||
11,1
|
||||
11,7
|
||||
9,7
|
||||
9,5
|
||||
2,5
|
||||
2,3
|
||||
7,3
|
||||
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