Published
Edited
Dec 6, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
answer = orbits.length
Insert cell
Insert cell
orbits = flatOrbits(OM)//.reverse())//.filter(v => v.includes('COM'))
Insert cell
flatOrbits = function (map) {
let endMatch, startMatch;
return map.reduce((a, d) => {
endMatch = a.filter(v => v.slice(-1) == d[0]);
startMatch = a.filter(v => v[0] == d[1]);
return a.concat([ //accumulate orbits
d, //the given direct orbit
...endMatch.map(v => v.concat(d[1])), //append to matching existing orbits
...startMatch.map(v => d.concat(v.slice(1))), //prepend to matching existing orbits
...endMatch.map(e => startMatch.map(s => e.concat(s))) //connect all pairs of matching orbits
.reduce((a, pair) => a.concat(pair), []) //flatten connected pairs
])}, []);
}

Insert cell
Insert cell
flatOrbits(test1.split('\n').map(v => v.split(")")))
Insert cell
Insert cell
transfers = youPath.length - pathTobranch.length - 1 + sanPath.length - pathTobranch.length - 1
Insert cell
Insert cell
Insert cell
roots = orbits.filter(o => o.includes('COM'))
Insert cell
youPath = roots.filter(o => o.includes('YOU'))[0]
Insert cell
sanPath = roots.filter(o => o.includes('SAN'))[0]
Insert cell
pathTobranch = youPath.filter((s,i) => s == sanPath[i])
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more