Problem 03 - Heart Delivery
Привет на всички!
В judge получавам 80/100 и не мога да открия какво пропускам.
Линк към условието: https://judge.softuni.org/Contests/Practice/DownloadResource/19413
Благодаря предварително!
function solve(arr) {
const houses = arr.shift().split('@').map(Number);
let cupidIndex = 0;
for (let input of arr) {
if (input === 'Love!') break;
input = input.split(' ');
const index = Number(input[1]);
cupidIndex = houses[cupidIndex + index] === undefined ? 0 : cupidIndex + index;
if (houses[cupidIndex] === 0) {
console.log(`Place ${cupidIndex} already had Valentine's day.`);
continue;
}
houses[cupidIndex] -= 2;
if (houses[cupidIndex] === 0) console.log(`Place ${cupidIndex} has Valentine's day.`);
}
console.log(`Cupid's last position was ${cupidIndex}.`);
if (houses.every(house => house === 0)) {
console.log('Mission was successful');
} else {
let housesCount = houses.filter(value => value !== 0);
console.log(`Cupid has failed ${housesCount.length} places.`);
}
}
Oh wow, you are hero! I spend so much time to try to find what in my logic is missing.
I didn't even think it could be a typo... :D
Thank you very much boss! Stay safe