Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let field = input
- .shift()
- .split("@")
- .map(Number);
- let startIndex = 0;
- for (const line of input) {
- if (line === `Love!`) {
- break;
- } else {
- let jump = Number(line.split(" ")[1]);
- let moveRight = jump % field.length;
- let currentEl = startIndex + moveRight;
- let newIndex = currentEl % field.length;
- startIndex = newIndex;
- let el = field.splice(newIndex, 1)[0];
- let a = 5;
- if (el === 0) {
- console.log(`Place ${newIndex} had valentines day`);
- } else {
- el -= 2;
- }
- field.splice(newIndex, 0, el);
- }
- }
- console.log(`Cupidon's last position was ${startIndex}`);
- let lengthField = field.filter(el => el != 0);
- if (lengthField.length === 0) {
- console.log(`Mission was successful.`);
- } else {
- console.log(`Cupidon has failed ${lengthField.length} places.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement