wip
This commit is contained in:
parent
b3cacb15de
commit
df0d7b92a3
66
2022/16/part1.js
Normal file
66
2022/16/part1.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import * as R from "remeda";
|
||||||
|
import u from "updeep";
|
||||||
|
|
||||||
|
import { readFile } from "../05/part1.js";
|
||||||
|
|
||||||
|
const parseLine = (line) => {
|
||||||
|
const {groups} = line.match( /Valve (?<valve>..).*flow rate=(?<flow>\d+).*valves? (?<exits>.*)/ );
|
||||||
|
return [ groups.valve, {
|
||||||
|
exits: groups.exits.split(',').map( x => x.trim() ),
|
||||||
|
flow: groups.flow
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
const readInput = (...args) =>
|
||||||
|
R.pipe(
|
||||||
|
readFile(...args),
|
||||||
|
(lines) => lines.split("\n"),
|
||||||
|
R.compact, // remove last line
|
||||||
|
R.map(parseLine),
|
||||||
|
Object.fromEntries,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const puzzleInput = readInput(import.meta.url, "input");
|
||||||
|
export const sample = readInput(import.meta.url, "sample");
|
||||||
|
|
||||||
|
function bestMoveFor(tunnels,minutesLeft,opened,location='AA',totalSteam=0,activeSteam=0) {
|
||||||
|
console.log(minutesLeft, totalSteam);
|
||||||
|
|
||||||
|
if(minutesLeft<=0) return totalSteam;
|
||||||
|
|
||||||
|
totalSteam += activeSteam;
|
||||||
|
|
||||||
|
const possibilities = [];
|
||||||
|
|
||||||
|
if(!opened.includes(location)) {
|
||||||
|
possibilities.push(
|
||||||
|
bestMoveFor(
|
||||||
|
tunnels,
|
||||||
|
minutesLeft-1,
|
||||||
|
[...opened, location],
|
||||||
|
location,
|
||||||
|
totalSteam,
|
||||||
|
activeSteam + tunnels[location].flow
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for( const exit of tunnels[location].exits ) {
|
||||||
|
possibilities.push(
|
||||||
|
bestMoveFor(
|
||||||
|
tunnels,
|
||||||
|
minutesLeft-1,
|
||||||
|
opened,
|
||||||
|
exit,
|
||||||
|
totalSteam,
|
||||||
|
activeSteam,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max( ...possibilities );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default (tunnels) => {
|
||||||
|
return bestMoveFor(tunnels,30,[]);
|
||||||
|
};
|
4
2022/16/part2.js
Normal file
4
2022/16/part2.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import * as R from "remeda";
|
||||||
|
|
||||||
|
|
||||||
|
export default () => {};
|
10
2022/16/sample
Normal file
10
2022/16/sample
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
|
||||||
|
Valve BB has flow rate=13; tunnels lead to valves CC, AA
|
||||||
|
Valve CC has flow rate=2; tunnels lead to valves DD, BB
|
||||||
|
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
|
||||||
|
Valve EE has flow rate=3; tunnels lead to valves FF, DD
|
||||||
|
Valve FF has flow rate=0; tunnels lead to valves EE, GG
|
||||||
|
Valve GG has flow rate=0; tunnels lead to valves FF, HH
|
||||||
|
Valve HH has flow rate=22; tunnel leads to valve GG
|
||||||
|
Valve II has flow rate=0; tunnels lead to valves AA, JJ
|
||||||
|
Valve JJ has flow rate=21; tunnel leads to valve II
|
29
2022/16/test.js
Normal file
29
2022/16/test.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { test, expect, describe } from "vitest";
|
||||||
|
|
||||||
|
import { expectSolution } from "../01/main.js";
|
||||||
|
import part1, { sample, puzzleInput } from "./part1.js";
|
||||||
|
import part2 from "./part2.js";
|
||||||
|
|
||||||
|
describe("part 1", () => {
|
||||||
|
test( "input", ()=> {
|
||||||
|
expect(sample).toMatchObject({AA: {
|
||||||
|
exists: [
|
||||||
|
'DD', 'II', 'BB',
|
||||||
|
],
|
||||||
|
flow: 0,
|
||||||
|
}})
|
||||||
|
|
||||||
|
} )
|
||||||
|
test.only("sample", () => {
|
||||||
|
expectSolution(part1(sample)).toEqual(1651);
|
||||||
|
});
|
||||||
|
test.todo("solution", () => {
|
||||||
|
expectSolution(part1(puzzleInput)).toEqual("TODO");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("part 2", () => {
|
||||||
|
test.todo("solution", () => {
|
||||||
|
expectSolution(part2(puzzleInput)).toEqual("TODO");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user