Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let symbols = gets();
- let N = gets().split(' ').map(Number);
- let souls = 0; // @
- let food = 0; //*
- let deadlock = 0; // x
- let arrSym = [];
- N.unshift(0);
- for(let i = 0;i < symbols.length;i++){
- arrSym.push(symbols[i]);
- }
- let moves = 0;
- let position = 0 ;
- for(let i = 0;i < N.length;i++){
- moves = N[i];
- if(moves < 0){
- position += moves;
- while(position < 0){
- position += arrSym.length;
- }
- }
- if(moves > 0){
- position += moves;
- while(position > arrSym.length - 1){
- position -= arrSym.length;
- }
- }
- switch(arrSym[position]){
- case "@" :
- souls ++;
- arrSym[position] = '0';
- break;
- case "*":
- food ++;
- arrSym[position] ='0';
- break;
- case "x" :
- if(position % 2 == 0){
- souls --;
- deadlock ++;
- arrSym[position] = '@';
- }
- else{
- deadlock ++;
- food --;
- arrSym[position] ='*';
- }
- break;
- default: break;
- }
- if(food < 0){
- print("You are deadlocked, you greedy kitty!" +'\n' + "Jumps before deadlock: " + i );
- return;
- }
- if(souls < 0){
- print("You are deadlocked, you greedy kitty!" +'\n' + "Jumps before deadlock: " + i );
- return;
- }
- }
- print("Coder souls collected: " + souls + `\n` +'Food collected: '+food + `\n` +"Deadlocks: "+deadlock);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement