Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yashikagarg13/ff87ae88007c0804b4d24fd92d971d3a to your computer and use it in GitHub Desktop.
Save yashikagarg13/ff87ae88007c0804b4d24fd92d971d3a to your computer and use it in GitHub Desktop.
Hacker Rank - Algorithms Practise 1
// https://www.hackerrank.com/challenges/compare-the-triplets
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var a0_temp = readLine().split(' ');
var a0 = parseInt(a0_temp[0]);
var a1 = parseInt(a0_temp[1]);
var a2 = parseInt(a0_temp[2]);
var b0_temp = readLine().split(' ');
var b0 = parseInt(b0_temp[0]);
var b1 = parseInt(b0_temp[1]);
var b2 = parseInt(b0_temp[2]);
function getScore(a, b) {
if (a > b) return [1, 0];
if (a < b) return [0, 1];
if (a == b) return [0, 0];
}
var scores = [getScore(a0, b0), getScore(a1, b1), getScore(a2, b2)];
scores = scores.reduce(function (memo, score) {
memo[0] += score[0];
memo[1] += score[1];
return memo;
}, [0, 0]);
console.log(scores.join(" "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment