jamaik

Untitled

Dec 6th, 2021
709
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.time("Do")
  2. let amounts = require("fs")
  3.     .readFileSync(`${__dirname}/inputs/day6.txt`,"utf8")
  4.     .split(",")
  5.     .reduce((s, t) => { s[t]++; return s }, new Array(9).fill(0));
  6.  
  7. const log = () => console.log(amounts.reduce((s, x) => s + x, 0));
  8.  
  9. [...Array(256)].forEach((_, i) => {
  10.     amounts = [...Array(9)].map((_,i) => {
  11.         let val = amounts[(i + 1) % 9];
  12.         if (i === 6) {
  13.             val += amounts[0];
  14.         }
  15.         return val;
  16.     });
  17.     i == 79 && log()
  18. });
  19. log();
  20. console.timeEnd("Do")
  21.  
RAW Paste Data