Skip to content

Instantly share code, notes, and snippets.

@franzese
Created March 28, 2020 21:19
Show Gist options
  • Save franzese/723c0498ff45872b2da579c3b9a655cb to your computer and use it in GitHub Desktop.
Save franzese/723c0498ff45872b2da579c3b9a655cb to your computer and use it in GitHub Desktop.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'fountainActivation' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY locations as parameter.
*/
function fountainActivation(locations) {
// Write your code here
let i = 0, fountainCount = 0;
while(i < locations.length) {
let fountainWidth = locations[i];
console.log(fountainWidth);
i += fountainWidth;
fountainCount++;
}
return fountainCount;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const locationsCount = parseInt(readLine().trim(), 10);
let locations = [];
for (let i = 0; i < locationsCount; i++) {
const locationsItem = parseInt(readLine().trim(), 10);
locations.push(locationsItem);
}
console.log(locations)
const result = fountainActivation(locations);
ws.write(result + '\n');
ws.end();
}
// [1,1,1] -> 1
// [1,1,3,1,1] -> 1
// [1,2,1,2,1] -> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment