const{readFile}=require('./reader');const{getTerms,calculateDistances}=require('./20-common');constfindMaxDistance=distances=>{return[...distances.values()].reduce((max,distance)=>Math.max(max,distance),0);}(async()=>{constinput=(awaitreadFile('20-input.txt'))[0];constroot=getTerms(input);constdistances=newMap();calculateDistances(distances,root);constmaxDistance=findMaxDistance(distances);console.log(`The largest number of doors you would be required to pass through to reach a room is ${maxDistance}`);})();

20b.js

const{readFile}=require('./reader');const{getTerms,calculateDistances}=require('./20-common');constgetRoomsWithMinDistance=(distances,minDistance)=>{return[...distances.values()].filter(distance=>distance>=minDistance).length;};(async()=>{constinput=(awaitreadFile('20-input.txt'))[0];constroot=getTerms(input);constdistances=newMap();calculateDistances(distances,root);constroomsWithMinDistance=getRoomsWithMinDistance(distances,1000);console.log(`The number of rooms which have a shortest path from your current location that pass through at least 1000 doors is ${roomsWithMinDistance}`);})();

For further actions, you may consider blocking this person and/or reporting abuse

We're a place where coders share, stay up-to-date and grow their careers.

## JavaScript solution

This was a very fun one, and I spent half of the time on the pen & paper figuring out how this tree would work.

As usual, I'm gonna omit reader.js which is the same as the other solutions and jump to the point:

## 20-common.js

## 20a.js

## 20b.js