Browse Source

Add solution for day 13 pt 1

ApisNecros 3 months ago
parent
commit
a72af90905
2 changed files with 12 additions and 1 deletions
  1. 12 1
      13/13_1.js
  2. 0 0
      13/input.dat

+ 12 - 1
13/13_1.js

@@ -1,6 +1,12 @@
 const util = require("util");
+const fs = require("node:fs");
 const Computer = require("../IntComp/Computer");
 
+// Load and parse the input
+const input = fs.readFileSync("./13/input.dat", "utf8")
+    .split(",")
+    .map((x) => parseInt(x, 10));
+
 const sampleInput = [104, 1, 104, 2, 104, 3, 104, 6, 104, 5, 104, 4, 99];
 
 const gameTiles = [
@@ -11,7 +17,7 @@ const gameTiles = [
     "°", // Ball
 ];
 
-const arcade = new Computer(sampleInput);
+const arcade = new Computer(input);
 arcade.Run();
 
 // console.log(arcade.outputValues);
@@ -32,6 +38,7 @@ function render(screenState) {
     let board = [];
     let boardWidth = -1;
     let boardHeight = -1;
+    let blockTileCount = 0;
 
     for (let i = 0; i < screenState.length; i += 3) {
         const x = screenState[i];
@@ -53,6 +60,9 @@ function render(screenState) {
 
     for (const row of board) {
         for (const tile of row) {
+            if (tile == 2) {
+                blockTileCount++;
+            }
             boardString += gameTiles[tile];
         }
         boardString += "\n";
@@ -60,6 +70,7 @@ function render(screenState) {
 
     console.clear();
     console.log(boardString);
+    console.log("\n", "Block tiles: ", blockTileCount);
 }
 
 function normalizeBoard(board, width, height) {

File diff suppressed because it is too large
+ 0 - 0
13/input.dat


Some files were not shown because too many files changed in this diff