Last active
August 4, 2016 23:35
-
-
Save mniehe/2531c2e4fa6ebcbb0d22bb60161abaca to your computer and use it in GitHub Desktop.
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
function processData(rawInput) { | |
var input = rawInput.split("\n").map(line => line.split(" ").map(value => parseInt(value))) | |
var [ counts, buffer, ...questions ] = input; | |
var [ n, k, q ] = counts; | |
var result = Array.from({length: buffer.length}); | |
questions = questions.reduce((last, current) => last.concat(current)) | |
buffer.forEach((value, oldPosition) => { | |
var newPosition = (k + oldPosition) % n; | |
result[newPosition] = value; | |
}); | |
questions.forEach(q => console.log(result[q])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment