Advertisement
Guest User

Untitled

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