Created
May 22, 2016 00:18
-
-
Save depeele/66656a73bf53773ae852f6613ae05876 to your computer and use it in GitHub Desktop.
HackerRank Javascript stdin using an ES6 generator and larger buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function* Lines( stream ) { | |
const EOL = require('os').EOL; | |
const Fs = require('fs'); | |
const buf = new Buffer(1024); | |
while (Fs.readSync(stream.fd, buf, 0, buf.length)) { | |
let lines = buf.toString().split( EOL ); | |
if (lines.length < 1) { break; } | |
for (let idex in lines) { | |
yield lines[idex]; | |
} | |
} | |
} | |
const lines = Lines( process.stdin ); | |
for (let T = 0, end = parseInt( lines.next().value ); T < end; T++) { | |
let N = parseInt( lines.next().value ); | |
// Do your work here. | |
console.log("%d", N); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment