Browse Source

commit lukes answer

karl.hudgell 4 years ago
parent
commit
2aac53782c
3 changed files with 369 additions and 5 deletions
  1. 9 0
      .vscode/launch.json
  2. 357 0
      Day 3/luke.js
  3. 3 5
      Day 3/part1.js

+ 9 - 0
.vscode/launch.json

@@ -48,6 +48,15 @@
                 "<node_internals>/**"
             ],
             "program": "${workspaceFolder}\\Day 3\\part1.js"
+        },
+        {
+            "type": "node",
+            "request": "launch",
+            "name": "Day3-Part1-luke",
+            "skipFiles": [
+                "<node_internals>/**"
+            ],
+            "program": "${workspaceFolder}\\Day 3\\luke.js"
         }
     ]
 }

+ 357 - 0
Day 3/luke.js

@@ -0,0 +1,357 @@
+const input = `....#...##......##..#..#.#...#.
+..######...#......#....#..#.##.
+..#.#...##......#.#..#..#....#.
+..#.....#..#.#........#.#..#..#
+#......##..###...#.#..#.....#..
+#.......##...###...#....#......
+.....##...#......##.#.#..#.##..
+.........#......#.....#......#.
+..#.#..#....#....#......##.#.##
+.#...#..#.............#.#..#.#.
+....#..#.#.##.#....#..#..#....#
+...#..#.....#.......#...#..#..#
+.....#.....#.......#..#...#....
+.##.......#...#..#........#...#
+...#.......#.#.#...#.#.#......#
+#....#..#.....#......##....#..#
+###.#......#.#.#.#..#....#....#
+......##......#.#...#...#..#...
+.....#......#.#.#......#.#.....
+...##...#..#........#..#.##....
+..##.#.#..#...###..........#.#.
+.#..#..#.....#.........#.###.#.
+....##.....#...#...##..#.##...#
+....#.##....#.....##......#....
+........#.#.........#.#.......#
+#....##.#....#..#...#..........
+#..###......#....##..........##
+....##.#.....#..#.##......#....
+#..#......#......#.............
+...##.....##.......#.......#...
+#...#.#.....#..........#...###.
+#.....#..#.#.###...#......###..
+...##.#......#........#..#.....
+......#.....###.#...##........#
+.#......##......##....#....#...
+..#.#..#.....##....#....#..#...
+..#.#.....#.##.#.....#.....#...
+....#.......#...#.........##...
+.#....#..#.......##.......#....
+..#..##.....#...##.##.#.#......
+.##.#....#............#.......#
+.......#...#..#.#.##.....##..##
+..###....#..#.##........##.#...
+....#.#..#.....#..#.#.....#....
+..#..#.#..............#..#.....
+.......#.#.#.........#......#..
+...##..#.#...#......##.#.......
+#....#.#.........#...#....#..##
+.#..#.#...#.......#.#.#....#.##
+.#..###.#..#.#.....#..#........
+#.#..##.###.....##.........#..#
+#...##...#..##..#..#..........#
+.#...#..#......................
+...##..###...........#.#...##..
+..........#.#....#.#...........
+..#....#....#..#....#.#.#......
+.#..#.....###......#...#...#...
+#.##..#..#.........#..#....#...
+........#......#...#.........#.
+..#.....#.#..##...#.#.#...##...
+..#...........#.##..#.#..#.##..
+..............##...#.#......#..
+#.#..#....#...##.###........#..
+.#...#..#........#........##..#
+.....##..#...#.....#.#.........
+.#...#...#....###...#.#.#..##..
+....#.........#....###..##....#
+.#....#...####...##....####.#..
+..#..#.......#..#......#.#.#...
+....#....#.......##..#.#.......
+..#....#...........##.#.##.....
+#..#..#...##.##....#.#.#.###.##
+...#...#....#.#...##...#....###
+......##........#.........#.#..
+....#####..#..##.......#.#....#
+....##..#...###....#..#.....#..
+..#........#..#.#.....#....#...
+..#....#......#..#...#......#..
+...#.....##...#.#..##.....#..#.
+...#..#.......####.##...#......
+.....#..#..#.##..##....#..#.#..
+..#..#..##.#.#.##..#..#...#....
+...#..........#.........#....##
+.##.....###...............#.##.
+...##...........#.#.#......#..#
+.#...#.#.##....#....#..#.......
+.#...###.#....#..#..#..#......#
+#..#........###...........#..#.
+..#...#......#.#.#......####.#.
+...#.#....##.#.....#.....##....
+...###..#.#.#...#.....#.###..#.
+.#.#..#...##......#..........#.
+##.....#.......#.#..###...#.#..
+##.###....#.....#.....###.#....
+#...#..##....#.#...#...#......#
+.....##.#........#.###.........
+.#..#..#.#......##.#...#.#.....
+#..#.#........##...........##.#
+#...###..#..####..#.#..........
+..#...#....#...##.#....#....##.
+......#.#........#.....#..#....
+#.........#...#.....#...#..##..
+#....#.........#...#.##..###.#.
+#...###...#.##.#.#.............
+#.#....#....#......#....#.#...#
+##...#.##......#..#.#....#.....
+....#...#.##....#..............
+.........##..........#..##..#..
+......##....#.#......#.........
+..#.#..............#......#..##
+...........##.......#.#.#......
+##...#........##.......#.#.....
+....#...#...#....#.#......##...
+...#..#.#.#.........#..#.#....#
+.##.#...#.#.........#.....##.#.
+#.#.....#.#.....#..............
+..#.#..#....#..........#..##...
+...#..#....................#..#
+...........#...........#...#..#
+............#...#............##
+..#....##......##...........#..
+..#..#..#....#....##......##.##
+##..........#..##.##.#...#.....
+............#..#........###.#..
+###...##.#.#....#....#.#....#..
+...#......##...#.......####....
+.......#..#..#.#.....#.........
+........##.......##.....#......
+#.#...#.###....#..#...##.......
+...#.#....#..#####.#..##.#.....
+..#.#..##.......###...#.....#..
+..#.......#..#...#...#..#.##...
+......#..#.......#.....#....#..
+.......#........#.#.......##..#
+.#.#.....#.......#.......##..#.
+..#.#....#.#.#####.....#...#...
+#..#............###.......#..#.
+........##.........#..#...###..
+.#............##...#.....#.....
+.#..##..#....#....#.......#....
+....##..........##.............
+.##..........#..#..#....#...#..
+...#..#..#............####.....
+.............#..#.##..#.#.##...
+.....#........#....#.#.......#.
+###.#..#.#...#....##...........
+....#......#...#....##.......#.
+.......#.#...#.#...#........##.
+..........#........#..#.##.....
+##..#.#.....##.#...............
+.....#....#................#...
+...##....#........##.#....#....
+.....##...###....#.#..#.......#
+.....#.#.........##....###.....
+.#.....##......#..##..##...##.#
+.#..............#.....#.#......
+.##......#..#..#......##.......
+.......#..................#....
+...#.#...##......####.........#
+#....#####.#.#..#..#..#...#...#
+##.#...#.......#....#...#...###
+...#........#.....#...#.##.....
+..##....#.......#....#.......##
+#......#..##...#..##.#.....#.#.
+..###........#.#..#........#.#.
+...#.###..........#.....#.#.#..
+#.###.....#...#...#..##..###...
+#....#.#.....#.#........#......
+........#.......##.......#.....
+...........#...#......##.......
+............#...#....#..#.....#
+#.#.#.#....#.....#.#..........#
+#.##...#...#..#....##.#.......#
+...#..#......#..#...##..##..#..
+#....#......#.#.....##.#..#....
+#....#..##.#......#.#.....#..##
+.#..##....##....#.#...#...#....
+#.#.###....#.#............#...#
+.#.#....#..#..........#....#.#.
+......#..#.#...............##..
+..#......###.#..........#.###..
+....#.##.#..#...##..#.#...#....
+..............#...##.......#.##
+.#...........#....#....#.##....
+#..#....#.....#...#.....##...#.
+.........#...#.##.......#...#.#
+.....#......#.........#.#..#...
+##..........#.#..##...#.#.#....
+##..##.#..#..#.....#.##....#...
+........##....#.#.#....#......#
+.#.##...#.###....#.........#..#
+..........#....###..#.........#
+#.#..#.#...#.......#..##.......
+..#....#...###..............##.
+#..###.....####...#..#..#...#..
+......#..#...###........###....
+..#.....#...#.......#....###..#
+.#.........#.#.#....#.#.......#
+#.#.###.#.#...........#........
+......#..#.........#........#..
+...........##.#........#.#...#.
+.....#.#......##.......#.....##
+...##...#............#..#.....#
+.....#..##....##...##.#..#.#...
+...#...#........#.#......##....
+........#..##..#..#......##.#..
+.#.#.....#.....#...........#.##
+.#...#.#............#......#...
+.....#...#........#....#..#.#..
+...##....#..#...#..............
+#....##.#.#............#.......
+#..#..#.....##..#........##.#.#
+##..#.#....#....##.......###..#
+.#.#.#.....###.....#.#......###
+.....#..#...###...#....#.#...#.
+.##.....................##....#
+.#.....#.........#....#.....##.
+#...#....#.#...###.......#.#..#
+...#.................#.#....#.#
+.##...#.#......................
+.##.#........#...##............
+.#....#.....#.........#.##..##.
+#......#...##..#.........##.##.
+......#......#...####..#.##....
+.###....#..##......#.##......#.
+..#...#....#..#.......#.#......
+#....#...#.................#.#.
+....#.#.#..#...#..#.......#.#.#
+#.#...##.......#.....##.#......
+#.........#.....##..##..#......
+....#..##..#.....#..#..#.#..#..
+......#.#..#.#.#....#.#.......#
+.##......#..#....##...##..#....
+..#..#......#...##..#.##.....#.
+..#..#.......#.#....#.....#...#
+....#.#.....###...#.......#.#..
+..#....##.....##.#........##...
+#...............##....#.....##.
+.#.........#....#...##.###.##.#
+.#.##..#.............#.#.#..#..
+.#.....#.................##....
+..####.........#.#......#.#..#.
+#.......#..........#.#........#
+.#.#...##.....#.#.......#....#.
+..#.##.#.......###....#....#...
+.#....##.............##.#.#.#..
+#.#.....#.#.#.#..#......##..#..
+.............#..........#.#.#..
+...#.#.............#.#...##....
+.......#..#.#.......#..#.#....#
+.............#.........###..#..
+.#.#..#....#.....#..#.....#...#
+#.....#....##..##.#..#........#
+..##..###.....##....#.#..#.....
+..#...##....#...#.#..........#.
+...##..##.#.....#....#.........
+..#...#........##.#..#........#
+#.............#.###......#.##..
+.#...#........#...........#...#
+..##.......#.#..##.##......#...
+...#.#...##....##..#...........
+.#......##........#....##....#.
+.........#..#....#...#..##.##..
+....#..#.#...#.......#.#.##....
+...#.#......#.#..#..#.#....#..#
+.......#........#.........###..
+#.#..#.#.........##............
+##..##..#.##..###...#.#...#....
+.#....#.#..#...#....#.##.....#.
+.#.#.#.#........##...#..#.#.##.
+.#..#.#..#...........#..#......
+..#.##.#...#....#.........#...#
+.....##...#.#...#...#....#.....
+..#..........#.#.#.......##.#..
+#.#............#..#.....#..#...
+..#...........##.#.##.#....#..#
+#..####.....#............#.....
+.##......#####.#..#.....#....#.
+...##..#.#......#.#..#..#...##.
+#....................#.##...#.#
+...#............#.............#
+....#.##..........#.....#......
+....##..##....#.#..............
+...........#....##.#.....#.....
+....#.....#....#....#......#...
+#...##........#...#........#.#.
+........#.....##..#.##.#..#.#.#
+....##......##....#.....##....#
+...#.#........##.......#...##..
+#......##..#.#.#....##......#..
+..#.......#.......##..#.##.....
+.#...#...#.#.............##....
+......#.#.#.........##...#..#.#
+.....#..####....#.##..........#
+...#...#.#....#.....#..#.....##
+.........#.......#......###....
+........##..##..#.#.#...###...#
+.#..##.#....#...##.....#.#.#...
+........##...#...##..#.........
+.........#.......#.##..#...####
+#......#.....#..............#.#
+##..##.#.##.....##...........#.
+#.............#.........#......
+...####.#.##..#.#.#.##.#......#
+..#.....##....#...#............
+#..............#......#...###..
+..#..#.#...#.##.........##.....
+..#...##..#........#..#.##..##.
+......###...#..#....#..#.###...
+...##.##.###.....##.#.......#..
+#....#..###..#.......#.#.#..#..
+..##.............##..##...###.#
+.#.#..#.........#..........#...
+.........#.#.....##...#..#...##
+....#..#....#####..#...#..#....
+...#.....#.....#...#.#..#.#....
+.#..#.............#.......##.#.
+...##.......#.#.....##......#..
+...........##..#.##..###...#.#.
+...........#...........#...#..#
+..#....#.##.#..#..#...........#
+..#.....##...#......#...#......
+...###.###.....##..........#..#`
+
+const dataLines = input.split("\n");
+
+function formatDataLine(dataLine) {
+    return dataLine.split("");
+};
+
+const map = dataLines.map(formatDataLine);
+
+const mapHeight = map.length;
+const mapWidth = map[0].length;
+const pointer = [0,0];
+
+function step(pointer, map, goRight, goDown) {
+    const x = pointer[0];
+    const y = pointer[1];
+    let newX = x + goRight;
+    let newY = y + goDown;
+    if (newX > (mapWidth - 1)) {
+        newX = newX - mapWidth;
+    }
+    pointer[0] = newX;
+    pointer[1] = newY;
+    // has to do y then x. [ row[col, col], ... ]
+    return map[pointer[1]][pointer[0]];
+}
+
+let treeCount = 0;
+while(pointer[1] < (mapHeight - 1)) {
+    const land = step(pointer, map, 3, 1);
+    if (land === "#") treeCount++;
+}
+
+console.log(treeCount);

+ 3 - 5
Day 3/part1.js

@@ -16,8 +16,6 @@ let totalLines = lines.length
 let dataArray = data.match(/.{1,31}/g)
 let stringSplit = data.split('')
 
-dataArray.forEach(element => {
-    console.log(stringSplit)
-    let t = element.charAt(right)
-    console.log(t)
-})
+let map = lines.map(stringSplit)
+
+console.log(map)