Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fs = require('fs');
  2.  
  3. fs.readFile('textfile.txt','utf8', (err, data) =>
  4. {
  5.   if (err) throw err;
  6.   var TempArray = data.split("\r\n")
  7.   var LineCounter = 0;
  8.   var IncreaseCounter = 0;
  9.   var LastIncrease = 0;
  10.   var Invested = false;
  11.  
  12.   for(var i = 0;i < TempArray.length;i++)
  13.   {
  14.     LineCounter++;
  15.         if(TempArray[i] > TempArray[i-1] && !Invested)
  16.         {
  17.             if(IncreaseCounter > 0 && LastIncrease == LineCounter - 1)
  18.             {
  19.                 IncreaseCounter++
  20.             }
  21.             else if(IncreaseCounter == 0)
  22.             {
  23.                 IncreaseCounter++
  24.             }
  25.             else
  26.             {
  27.                 IncreaseCounter == 0;
  28.             }
  29.  
  30.             LastIncrease = LineCounter;
  31.             if(IncreaseCounter == 3)
  32.             {
  33.                 console.log("Purchase ducats on line ", LineCounter)
  34.                 Invested = true;
  35.                 IncreaseCounter = 0;
  36.             }
  37.         }
  38.         if(Invested)
  39.         {
  40.             if(TempArray[i] < TempArray[i-1])
  41.             {
  42.                 console.log("Sell ducats on line ", LineCounter);
  43.                 Invested = false;
  44.             }
  45.         }
  46.     }
  47. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement