mosredna

AoC 2022 day 1

Dec 1st, 2022 (edited)
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.53 KB | Software | 0 0
  1. const fs = require('fs');
  2. const eol = require('os').EOL;
  3. const arg = process.argv.slice(2);
  4. const file = arg[0] == "test" ? "/test.txt" : "/data.txt";
  5. const startTime = new Date().getTime();
  6.  
  7. let input = fs.readFileSync(__dirname + file, 'utf8');
  8. let data = input.split(eol + eol).map(val =>
  9.     val.split(eol).map(Number).reduce((a, b) => a + b)
  10. ).sort((a, b) => b - a)
  11.  
  12. console.log('Part 1: ' + data[0]);
  13. console.log('Part 2: ' + (data[0] + data[1] + data[2]));
  14.  
  15. console.log('Timer: ' + (new Date().getTime() - startTime) + 'ms');
Advertisement
Add Comment
Please, Sign In to add comment