Skip to content

Instantly share code, notes, and snippets.

@emplv
Created December 6, 2019 07:39
Show Gist options
  • Select an option

  • Save emplv/76f1da362392be9e553aec6a818d1446 to your computer and use it in GitHub Desktop.

Select an option

Save emplv/76f1da362392be9e553aec6a818d1446 to your computer and use it in GitHub Desktop.
AoC 2019 - day 6
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