Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Christmass Spirit
- function xmassSpirit(input){
- let maxQuant=Number(input[0]);
- let days=Number(input[1]);
- let spirit=0;
- let cost=0;
- for (let i=1; i<=days; i++){
- if (i%11===0){
- maxQuant+=2;
- }
- if (i%2===0){
- cost+=maxQuant*2;
- spirit+=5;
- }
- if (i%3===0){
- cost+=(maxQuant*5)+(maxQuant*3);
- spirit+=13;
- }
- if (i%5===0){
- cost+=maxQuant*15;
- spirit+=17;
- if (i%3===0){
- spirit+=30;
- }
- }
- if (i%10===0){
- spirit-=20;
- cost+=23;
- }
- }
- if (days%10==0){
- spirit-=30;
- }
- console.log(`Total cost: ${cost}`);
- console.log(`Total spirit: ${spirit}`)
- }
- 2. Santa's List
- function santasList(input){
- let kidsList=input.shift()
- .split("&");
- let commandsArr=input;
- commandsArr.pop();
- for (let i=0; i<commandsArr.length; i++){
- let command=commandsArr[i].split(" ");
- if (command.includes("Good")){
- let goodKid=command[1];
- if (kidsList.includes(goodKid)){
- let indexOfGoodKid=kidsList.indexOf(goodKid);
- kidsList.splice(indexOfGoodKid,1);
- }
- } else if (command.includes("Bad")){
- let badKid=command[1];
- if (!kidsList.includes(badKid)){
- kidsList.unshift(badKid);
- }
- } else if(command.includes("Rename")){
- let oldName=command[1];
- let newName=command[2];
- if (kidsList.includes(oldName)){
- let indexOfOldName=kidsList.indexOf(oldName);
- kidsList.splice(indexOfOldName,1,newName);
- }
- } else if (command.includes("Rearrange")){
- let name=command[1];
- if (kidsList.includes(name)){
- let indexOfName=kidsList.indexOf(name);
- kidsList.splice(indexOfName,1);
- kidsList.push(name);
- }
- }
- }
- console.log(kidsList.join(", "));
- }
- 3. Present Delivery
- function presentDelivery(input){
- let housesArr=input.shift()
- .split("@");
- housesArr=housesArr.map(Number);
- let jumpCommands=input;
- let position=0;
- let landedAt=0;
- for (let i=0; i<jumpCommands.length-1;i++){
- let command=jumpCommands[i];
- if (command.includes("Merry Xmas!")){
- break;
- } else {
- let jumpArr=command.split(" ");
- let jumpLength=Number(jumpArr[1]);
- landedAt=position+jumpLength;
- while (landedAt>=housesArr.length){
- landedAt=landedAt-(housesArr.length);
- }
- position=landedAt;
- if (housesArr[landedAt]>=2){
- housesArr[landedAt]-=2;
- } else {
- console.log(`House ${landedAt} will have a Merry Christmas.`);
- }
- }
- }
- console.log(`Santa's last position was ${landedAt}.`);
- let failedHouses=0;
- housesArr.forEach(house => {
- if (house!==0){
- failedHouses++;
- }
- });
- if (failedHouses!==0){
- console.log(`Santa has failed ${failedHouses} houses.`);
- } else {
- console.log(`Mission was successful.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement