Guest User

Untitled

a guest
Jun 4th, 2020
50
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let index = 0;
  3.   let seats = Number(input[index++]);
  4.   let usedSeats = 0;
  5.   let income = 0;
  6.  
  7.   while (true) {
  8.     let command = input[index++];
  9.     if (command === 'Movie time!') {
  10.       console.log(`There are ${seats - usedSeats} seats left in the cinema.`);
  11.       break;
  12.     }
  13.  
  14.     let people = Number(command);
  15.     if (usedSeats + people > seats) {
  16.       console.log(`The cinema is full.`);
  17.       break;
  18.     }
  19.  
  20.     usedSeats += people;
  21.  
  22.     income += command * 5;
  23.    
  24.     if (people % 3 === 0) {
  25.       income -= 5;
  26.     }
  27.   }
  28.  
  29.   console.log(`Cinema income - ${income} lv.`);
  30. }
RAW Paste Data