import { bidirectional } from 'graphology-shortest-path'; import * as R from "remeda"; import u from 'updeep'; import { buildGraph } from './part1.js'; const findMaxSteam = (tunnels,graph) => (minutesLeft, unopened, opened, activeSteam, peeps ) => { if (minutesLeft <= 0) return 0; if (unopened.length === 0) return minutesLeft * activeSteam; const next = R.first( R.sortBy(peeps, R.prop('eta'))); if( next.eta >) } function finalSteam(tunnels, graph, minutesLeft, possibilities, locations, activeSteam = 0) { const nextToGo = locations.filter(([time]) => !time); for( const l of locations) { if( l[0] === 0 ) { activeSteam += l[2]; l[2] = 0; } } let scores = []; for ( const ntg of nextToGo ) { for ( const next of possibilities ) { const path = bidirectional(graph, ntg[1], next); //console.log(path); 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 { //console.log({totalSteam, time, activeSteam}); let ts = time * activeSteam; scores.push( ts + finalSteam( tunnels, graph, minutesLeft - time, possibilities.filter( x => x !== next ), locs.map( ([t,dest,s] ) => [ t -time, dest,s ]), activeSteam ) ) } } } return Math.max( ...scores ); } export default (tunnels) => { const possibilities = Object.keys(tunnels).filter( k => tunnels[k].flow ); const graph = buildGraph(tunnels); return finalSteam(tunnels, graph, 26, possibilities, [ [ 0, 'AA',0 ], [ 0, 'AA',0 ] ], 0, 0) };