Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pipes(str) {
  2.  
  3.     var f = str[0];
  4.     var n = f.split("\n").map(Number);
  5.     var V = Number(n[0]);
  6.     var P1 = Number(n[1]);
  7.     var P2 = Number(n[2]);
  8.     var H = Number(n[3]);
  9.  
  10.     var fillingInLitres = H * (P1 + P2);
  11.     var fillingPercent = fillingInLitres / V;
  12.     var overflow = fillingInLitres - V;
  13.     var p1ShareT = (P1 * H) / fillingInLitres;
  14.     var p2ShareT = (P2 * H) / fillingInLitres;
  15.  
  16.     if (fillingInLitres <= V) {
  17.         console.log("The pool is " + Math.floor(fillingPercent * 100) + "% full. Pipe 1: " + Math.floor(p1ShareT * 100) + "%. Pipe 2: " + Math.floor(p2ShareT * 100) + "%.");
  18.  
  19.     } else {
  20.         console.log("For " + H + " hours the pool overflows with " + overflow + " liters.");
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement