Advertisement
pacho_the_python

Untitled

Jun 17th, 2023
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. function theLift(data) {
  2.     let tourists = Number(data[0])
  3.     let lift = data[1].split(' ').map(Number)
  4.     let counter = 0
  5.     let maxSLots = 4
  6.     while (tourists > 0) {
  7.         if (counter === lift.length) {
  8.             break
  9.         }
  10.         let freeSlots = maxSLots - lift[counter]
  11.         if (freeSlots > 0) {
  12.             if (tourists > freeSlots) {
  13.                 lift[counter] += freeSlots
  14.                 tourists -= freeSlots
  15.             } else {
  16.                 lift[counter] += tourists
  17.                 tourists = 0
  18.             }
  19.         }
  20.         counter += 1
  21.     }
  22.     if (lift[lift.length-1] < maxSLots && tourists === 0) {
  23.         console.log("The lift has empty spots!")
  24.        
  25.     } else if (lift[lift.length-1] === maxSLots && tourists > 0) {
  26.         console.log(`There isn't enough space! ${tourists} people in a queue!`)
  27.        
  28.    }
  29.    console.log(lift.join(' '))
  30.        
  31. }
  32.  
  33. theLift(["20", "0 2 0"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement