@@ -0,0 +1,7 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="2025-12" type="BunRunConfiguration">
|
||||||
|
<option name="program" value="2025/12/run.ts" />
|
||||||
|
<option name="workingDirectory" value="$PROJECT_DIR$" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { describe, it } from 'bun:test';
|
||||||
|
|
||||||
|
describe('2025-12', () => {
|
||||||
|
it('first', () => {
|
||||||
|
const testInput = `0:
|
||||||
|
###
|
||||||
|
##.
|
||||||
|
##.
|
||||||
|
|
||||||
|
1:
|
||||||
|
###
|
||||||
|
##.
|
||||||
|
.##
|
||||||
|
|
||||||
|
2:
|
||||||
|
.##
|
||||||
|
###
|
||||||
|
##.
|
||||||
|
|
||||||
|
3:
|
||||||
|
##.
|
||||||
|
###
|
||||||
|
##.
|
||||||
|
|
||||||
|
4:
|
||||||
|
###
|
||||||
|
#..
|
||||||
|
###
|
||||||
|
|
||||||
|
5:
|
||||||
|
###
|
||||||
|
.#.
|
||||||
|
###
|
||||||
|
|
||||||
|
4x4: 0 0 0 0 2 0
|
||||||
|
12x5: 1 0 1 0 2 2
|
||||||
|
12x5: 1 0 1 0 3 2`;
|
||||||
|
// Doesn't work on test data
|
||||||
|
// expect(solveFirst(testInput)).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { sumBy } from '../../utils/array.ts';
|
||||||
|
|
||||||
|
export function solveFirst(input: string): number {
|
||||||
|
const rawShapes = input.split('\n\n');
|
||||||
|
const regions = rawShapes
|
||||||
|
.pop()!
|
||||||
|
.split('\n')
|
||||||
|
.map((row) => {
|
||||||
|
const [size, count] = row.split(': ');
|
||||||
|
const [wide, long] = size.split('x').map(Number);
|
||||||
|
|
||||||
|
return { wide, long, count: count.split(' ').map(Number) };
|
||||||
|
});
|
||||||
|
const shapes = rawShapes.map((s) => s.split('\n').slice(1));
|
||||||
|
const shapeWeight = shapes.map((s) =>
|
||||||
|
sumBy(s, (r) => [...r.matchAll(/#/g)].length)
|
||||||
|
);
|
||||||
|
|
||||||
|
// works for the actual data, not for testing lmao
|
||||||
|
const possible = regions.filter(
|
||||||
|
(r) => r.long * r.wide >= sumBy(r.count, (e, i) => e * shapeWeight[i])
|
||||||
|
);
|
||||||
|
return possible.length;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { join } from 'path';
|
||||||
|
import { solveFirst } from './index.ts';
|
||||||
|
|
||||||
|
const input = await Bun.file(join(__dirname, 'input.txt')).text();
|
||||||
|
|
||||||
|
const firstAnswer = solveFirst(input);
|
||||||
|
|
||||||
|
console.log(firstAnswer);
|
||||||
+2
-2
@@ -14,9 +14,9 @@ export function sumArray(arr: ReadonlyArray<number>): number {
|
|||||||
*/
|
*/
|
||||||
export function sumBy<E>(
|
export function sumBy<E>(
|
||||||
arr: ReadonlyArray<E>,
|
arr: ReadonlyArray<E>,
|
||||||
by: (element: E) => number | string
|
by: (element: E, index: number) => number | string
|
||||||
): number {
|
): number {
|
||||||
return arr.reduce((sum, element) => sum + Number(by(element)), 0);
|
return arr.reduce((sum, element, i) => sum + Number(by(element, i)), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user