SHARE
TWEET

Untitled

a guest Sep 23rd, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function search(row, column) {
  2.     if (row < 0 || row >= rowsCount)
  3.         return 0;
  4.  
  5.     if (column < 0 || column >= columnsCount)
  6.         return 0;
  7.  
  8.     if (house[row][column] === "#")
  9.         return 0;
  10.  
  11.     if (house[row][column] === "~")
  12.         return 0;
  13.  
  14.     house[row][column] = "~";
  15.  
  16.     return 1 + search(row, column + 1) + search(row, column - 1) + search(row + 1, column);
  17. }
  18.  
  19. function startFlowProcess() {
  20.     var cellsCount = 0;
  21.     for (var i = 0; i < columnsCount; i++) {
  22.         cellsCount += search(0, i);
  23.     }
  24.  
  25.     return cellsCount;
  26. }
  27.  
  28. var building = require("fs").readFileSync("./solution-2-building.txt", { encoding: "utf-8" });
  29. var houseAsStrings = building.split("\r\n");
  30.  
  31. var rowsCount = houseAsStrings.length;
  32. var columnsCount = houseAsStrings[0].length;
  33.  
  34. var house = new Array(columnsCount);
  35.  
  36. for (var i = 0; i < rowsCount; i++) {
  37.     house[i] = new Array(columnsCount);
  38.     for (var j = 0; j < columnsCount; j++) {
  39.         house[i][j] = houseAsStrings[i][j];
  40.     }
  41. }
  42.  
  43. var count = startFlowProcess();
  44.  
  45. console.log(count);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top