Skip to content

Instantly share code, notes, and snippets.

@mniehe
Last active August 4, 2016 23:35
Show Gist options
  • Save mniehe/2531c2e4fa6ebcbb0d22bb60161abaca to your computer and use it in GitHub Desktop.
Save mniehe/2531c2e4fa6ebcbb0d22bb60161abaca to your computer and use it in GitHub Desktop.
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