part-01.ts (849B)
1 import { lineByLine } from './line-by-line'; 2 3 let lastDepth = null; 4 let increasedTotal = 0; 5 6 let texts = [ 7 'decreased', 8 'no change', 9 'increased', 10 ]; 11 12 (async () => { 13 14 await lineByLine(__dirname + '/input', line => { 15 if ((!line) || isNaN(line)) return; 16 17 const depth = parseInt(line); 18 if (null === lastDepth) { 19 process.stdout.write(`${depth} (N/A - no previous measurement)\n`); 20 } else { 21 const increased = (depth > lastDepth) | 0; 22 const decreased = (depth < lastDepth) | 0; 23 increasedTotal += increased; 24 25 process.stdout.write(`${depth} (${texts[1 + increased - decreased]})\n`); 26 } 27 lastDepth = depth; 28 }); 29 30 process.stdout.write('\n\n'); 31 process.stdout.write('---[ REPORT ]---\n'); 32 process.stdout.write(`Increased ${increasedTotal} times\n`); 33 process.stdout.write('\n'); 34 35 })(); 36