Created
December 6, 2019 07:39
-
-
Save emplv/76f1da362392be9e553aec6a818d1446 to your computer and use it in GitHub Desktop.
AoC 2019 - day 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const INPUT = ` | |
| COPY & PASTE HERE | |
| `.trim``.split`\n`; | |
| // prepare orbit map | |
| INPUT.map(x=>o[[s,y]=x.split`)`,y]=s,o={}); // o == all orbits | |
| // Part 1 | |
| c={}; // cache | |
| a=k=>c[k]||(o[k]?c[k]=1+a(o[k]):0); // get all orbiters count | |
| t=Object.keys(o).reduce((t,c)=>t+a(c),0); // count total | |
| // Part 2 | |
| b=k=>(s=o[k])?[s,...b(s)]:[]; // get all orbits up to K | |
| Y=b('YOU'); // all orbits up to YOU | |
| S=b('SAN'); // all orbits up to SANTA | |
| d=(f=i=>~(x=S.findIndex(s=>s==Y[i]))?x-+-i:f(i+1))(0); // get orbit jump count | |
| // |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment