Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //heart delivery
- function solve(array) {
- let position = 0;
- let count = 0;
- let index = 0;
- let slice = 0;
- let neighborhood = array.shift().split('@');
- for (let i = 0; i < array.length; i ++ ){
- command = array[i];
- while (command !== 'Love!'){
- let [jumps, step] = command.split(' ');
- position = Number(step) + Number(index)
- if(neighborhood.length <= position){
- index = 0;
- position = 0;
- neighborhood[index] -= 2;
- slice = Number(neighborhood[index]);
- if(count >= 1){
- console.log(`Place ${position} already had Valentine's day.`);
- }else {
- console.log(`Place ${position} has Valentine's day.`);
- }
- count++
- break;
- }else{
- let positive = Number(neighborhood[position]);
- if(positive > 0){
- neighborhood[Number(step) + Number(index)] -= 2;
- slice = Number(neighborhood[position]);
- index = step;
- }
- }
- if(slice <= 0){
- console.log(`Place ${position} has Valentine's day.`);
- }
- break;
- }
- }
- console.log(`Cupid's last position was ${position}.`);
- console.log(`Cupid has failed ${position} places.`);
- }
- solve([ '10@10@10@2', 'Jump 1', 'Jump 2', 'Love!' ])
- solve(["2@4@2","Jump 2","Jump 2","Jump 8","Jump 3","Jump 1","Love!"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement