namespace AdventOfCode2019_03_1 { const DAY = 3; const PROBLEM = 1; class Mov { dir: string; len: number; constructor(v: string) { this.dir = v[0]; this.len = parseInt(v.substr(1)); } } class Pos { x: number; y: number; constructor(x: number, y: number) { this.x = x; this.y = y; } manhatten() { return Math.abs(this.x)+Math.abs(this.y); } ident() { return this.x*10000+this.y; } static manhattenCompare(a: Pos, b: Pos): number { const aa = a.manhatten(); const bb = b.manhatten(); if (aa>bb) return +1; if (aa p.trim().length > 0) .map(p => p.split(",").map(q => new Mov(q)) ) .map(p => getPath(p)); const path1 = xin[0]; const path2 = xin[1]; let intersections = []; let p1hash: { [_:number]:Pos } = {}; for(let p1 of path1) p1hash[p1.ident()] = p1; for(let p2 of path2) { if (p2.ident() in p1hash) intersections.push(p2); } intersections.sort((a,b) => Pos.manhattenCompare(a, b)) AdventOfCode.output(DAY, PROBLEM, intersections[0].manhatten().toString()); } }