Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pipes(str) {
- var f = str[0];
- var n = f.split("\n").map(Number);
- var V = Number(n[0]);
- var P1 = Number(n[1]);
- var P2 = Number(n[2]);
- var H = Number(n[3]);
- var fillingInLitres = H * (P1 + P2);
- var fillingPercent = fillingInLitres / V;
- var overflow = fillingInLitres - V;
- var p1ShareT = (P1 * H) / fillingInLitres;
- var p2ShareT = (P2 * H) / fillingInLitres;
- if (fillingInLitres <= V) {
- console.log("The pool is " + Math.floor(fillingPercent * 100) + "% full. Pipe 1: " + Math.floor(p1ShareT * 100) + "%. Pipe 2: " + Math.floor(p2ShareT * 100) + "%.");
- } else {
- console.log("For " + H + " hours the pool overflows with " + overflow + " liters.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement