SHARE
TWEET

Untitled

a guest Dec 13th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let fs = require("fs")
  2. let Robot = require("./hoover").Robot
  3.  
  4.  
  5.  
  6. const readFile = () => fs.readFile("./input.txt", 'utf8', function(err, data) {
  7.  
  8.     if(err){
  9.         throw err;
  10.     }
  11.  
  12.  
  13.     let contents = data
  14.     processFile(contents)
  15.  
  16. });
  17.  
  18. let result;
  19.  
  20. let x_limit;
  21. let y_limit;
  22.  
  23. let x;
  24. let y;
  25.  
  26. let twoDimensionArray;
  27.  
  28.  
  29. function processFile(contents){
  30.     result = contents.split("\n").filter(item => item.length > 0);
  31.  
  32.     let gridDimensions = result[0].split(" ");
  33.     x_limit = parseInt(gridDimensions[0] , 10)
  34.     y_limit = parseInt(gridDimensions[1] , 10)
  35.  
  36.     let initalPosition = result[1].split(" ")
  37.     x = parseInt(initalPosition[0] , 10);
  38.     y = parseInt(initalPosition[1] , 10);
  39.  
  40.  
  41.  
  42.      twoDimensionArray = []
  43.  
  44.     for (let i = 2; i < result.length - 1; i++){
  45.         let small_array = []
  46.         let dirtCoordinate = result[i].split(" ")
  47.  
  48.         let x_dirt = parseInt(dirtCoordinate[0], 10)
  49.         let y_dirt = parseInt(dirtCoordinate[1], 10)
  50.  
  51.         small_array.push(x_dirt)
  52.         small_array.push(y_dirt)
  53.         twoDimensionArray.push(small_array)
  54.     }
  55.  
  56.     let rumba = new Robot(x, y, twoDimensionArray)
  57.     rumba.obtainRoomDimensions(x_limit, y_limit)
  58.     rumba.processInstructions(result[result.length - 1])
  59.  
  60.  
  61. }
  62.  
  63. readFile();
  64.  
  65. module.exports =  {processFile, x , y , x_limit, y_limit, twoDimensionArray}
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top