wip
This commit is contained in:
parent
1a855600cf
commit
231cc7b883
@ -4,13 +4,12 @@ import * as R from "remeda";
|
||||
import { buildGraph } from './part1.js';
|
||||
|
||||
function finalSteam(tunnels, graph, minutesLeft, possibilities, locations, activeSteam = 0) {
|
||||
//console.log(minutesLeft, activeSteam, locations, possibilities);
|
||||
|
||||
if (minutesLeft <= 0) return 0;
|
||||
|
||||
if (possibilities.length === 0) return minutesLeft * activeSteam;
|
||||
|
||||
const nextToGo = locations.find(([time]) => !time);
|
||||
const nextToGo = locations.filter(([time]) => !time);
|
||||
|
||||
for( const l of locations) {
|
||||
if( l[0] === 0 ) {
|
||||
@ -22,18 +21,21 @@ function finalSteam(tunnels, graph, minutesLeft, possibilities, locations, activ
|
||||
|
||||
let scores = [];
|
||||
|
||||
for ( const ntg of nextToGo ) {
|
||||
|
||||
for ( const next of possibilities ) {
|
||||
const path = bidirectional(graph, nextToGo[1], next);
|
||||
const path = bidirectional(graph, ntg[1], next);
|
||||
|
||||
//console.log(path);
|
||||
|
||||
const locs = locations.map( x => x === nextToGo ? [
|
||||
const locs = locations.map( x => x === ntg ? [
|
||||
path.length, next, tunnels[next].flow
|
||||
] : x );
|
||||
|
||||
let time = Math.min( ...locs.map( ([time]) => time ) );
|
||||
|
||||
if (time >= minutesLeft) {
|
||||
//console.log(minutesLeft, activeSteam, locations, possibilities);
|
||||
scores.push( minutesLeft * activeSteam );
|
||||
}
|
||||
else {
|
||||
@ -44,13 +46,14 @@ function finalSteam(tunnels, graph, minutesLeft, possibilities, locations, activ
|
||||
ts + finalSteam(
|
||||
tunnels, graph, minutesLeft - time,
|
||||
possibilities.filter( x => x !== next ),
|
||||
locs.map( ([t,dest] ) => [ t -time, dest ]),
|
||||
locs.map( ([t,dest,s] ) => [ t -time, dest,s ]),
|
||||
activeSteam
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return Math.max( ...scores );
|
||||
}
|
||||
@ -65,8 +68,8 @@ export default (tunnels) => {
|
||||
const graph = buildGraph(tunnels);
|
||||
|
||||
return finalSteam(tunnels, graph, 26, possibilities, [
|
||||
[ 0, 'AA' ],
|
||||
[ 0, 'AA' ]
|
||||
[ 0, 'AA',0 ],
|
||||
[ 0, 'AA',0 ]
|
||||
], 0, 0)
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user