Advertisement
scibuff

Advent of Code 2023 - Day 21 - Parser

Dec 21st, 2023
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.62 KB | Source Code | 0 0
  1. const key = (i, j) => {
  2.   return `${i},${j}`;
  3. };
  4. const parse = (input) => {
  5.   const grid = utils.getInputLines(input).map((e) => e.trim().split(""));
  6.   const walls = {};
  7.   const plots = {};
  8.   let start = { i: 0, j: 0 };
  9.   for (let i = 0; i < grid.length; i++) {
  10.     for (let j = 0; j < grid[i].length; j++) {
  11.       const value = grid[i][j];
  12.       if (value == "#") {
  13.         walls[key(i, j)] = true;
  14.       }
  15.       if (value == "S") {
  16.         plots[key(i, j)] = -1;
  17.         start = { i: i, j: j };
  18.       }
  19.     }
  20.   }
  21.   return {
  22.     walls: walls,
  23.     plots: plots,
  24.     start: start,
  25.     size: grid.length,
  26.   };
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement