Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- archeryTournament = (input) => {
- let points = 0;
- let targets = input.shift().split('|').map(Number);
- while((line = input.shift()) !== 'Game over') {
- if(line === 'Reverse') {
- targets.reverse();
- } else {
- let [ direction, index, length ] = line.split(' ')[1].split('@');
- index = Number(index);
- length = Number(length);
- if(targets[index] === undefined) {
- continue;
- }
- while(length-- > 0) {
- index = index + (direction === 'Left' ? -1 : 1);
- if(index === -1) {
- index = targets.length - 1;
- } else if (index === targets.length) {
- index = 0;
- }
- }
- points += targets[index] >= 5 ? 5 : targets[index];
- targets[index] = (value = targets[index] - 5) >= 0 ? value : 0;
- }
- }
- console.log(targets.join(' - '));
- console.log(`Iskren finished the archery tournament with ${points} points!`);
- };
Advertisement
Add Comment
Please, Sign In to add comment