Created
September 16, 2016 09:42
-
-
Save yashikagarg13/8c85d99fc860e20494b73e33f25c937e to your computer and use it in GitHub Desktop.
Problem Solving in Funtional Programming Way - Sep 16, 2016
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
//https://www.hackerrank.com/challenges/circular-array-rotation | |
function processData(input) { | |
var inputSplit = input.split("\n"); | |
var n = Number(inputSplit[0].split(" ")[0]); | |
var k = Number(inputSplit[0].split(" ")[1]); | |
var q = Number(inputSplit[0].split(" ")[2]); | |
var arr = inputSplit[1].split(" ").map(Number); | |
var newArr = (Array(k).fill()).reduce(function(memo, item) { | |
var ele = memo.pop(); | |
memo.unshift(ele); | |
return memo; | |
}, arr.slice(0)); | |
var results = inputSplit.slice(2).map(function(item) { | |
return newArr[Number(item)]; | |
}); | |
console.log(results.join("\n")); | |
} | |
process.stdin.resume(); | |
process.stdin.setEncoding("ascii"); | |
_input = ""; | |
process.stdin.on("data", function (input) { | |
_input += input; | |
}); | |
process.stdin.on("end", function () { | |
processData(_input); | |
}); |
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
// 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