Spocoman

02. Hospital

Dec 25th, 2021 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hospital(input) {
  2.     let period = Number(input[0]);
  3.     let treated = 0;
  4.     let untreated = 0;
  5.     let doctors = 7;
  6.  
  7.     for (let i = 1; i <= period; i++) {
  8.         let patients = Number(input[i]);
  9.         if (untreated > treated && i % 3 === 0){
  10.             doctors++;
  11.         }
  12.         if (patients > doctors){
  13.             treated += doctors;
  14.             untreated += patients - doctors;
  15.         } else{
  16.             treated += patients;
  17.         }
  18.     }
  19.     console.log(`Treated patients: ${treated}.`);
  20.     console.log(`Untreated patients: ${untreated}.`);
  21. }
  22.  
Add Comment
Please, Sign In to add comment