# Pipes In Pool

Jun 3rd, 2020
815
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //02. Pipes In Pool.js
2. function pipesInPool(arr) {
3.   'use strict'
4.
5.   let input = arr[0].split('\n')
6.
7.   let volumeLitres = Number(input[0])
8.   let p1LitresPerHour = Number(input[1])
9.   let p2LitresPerHour = Number(input[2])
10.   let hNoWorker = Number(input[3])
11.
12.   let waterLitres = (p1LitresPerHour * hNoWorker) + (p2LitresPerHour * hNoWorker)
13.
14.   if (waterLitres <= volumeLitres) {
15.     let percent = Math.trunc(waterLitres / volumeLitres * 100)
16.     let percent1 = Math.trunc(p1LitresPerHour * hNoWorker / waterLitres * 100)
17.     let percent2 = Math.trunc(p2LitresPerHour * hNoWorker / waterLitres * 100)
18.
19.     console.log(`The pool is \${percent}% full. Pipe 1: \${percent1}%. Pipe 2: \${percent2}%.`)
20.   } else {
21.     console.log(`For \${hNoWorker} hours the pool overflows with \${waterLitres - volumeLitres} liters.`)
22.   }
23. }
24. pipesInPool(['1000\n100\n120\n3'])
25. pipesInPool(['100\n100\n100\n2.5'])
26.
27. function pipesInPool0(arr) {
28.
29.   let input = arr[0].split('\n')
30.
31.   let volume = parseInt(input[0])
32.   let pipe1 = parseInt(input[1])
33.   let pipe2 = parseInt(input[2])
34.   let hours = +input[3]
35.
36.   let water = (pipe1 + pipe2) * hours;
37.
38.   if (water <= volume) {
39.     console.log(
40.       `The pool is \${~~((water / volume) * 100.0)}% full. Pipe 1: \${~~((pipe1 * hours) / water * 100.0)}%. Pipe 2: \${~~(((pipe2 * hours) / water) * 100.0)}%.`);
41.   }
42.   else {
43.     console.log(
44.       `For \${hours} hours the pool overflows with \${water - volume} liters.`);
45.   }
46. }
47.
48.
49. function pipesInPool2(arr) {
50.
51.   let input = arr[0].split('\n')
52.
53.   let volume = Number(input[0])
54.   let p1 = Number(input[1])
55.   let p2 = Number(input[2])
56.   let hours = Number(input[3])
57.
58.   let pipe1 = p1 * hours;
59.   let pipe2 = p2 * hours;
60.
61.   let pipePool = pipe1 + pipe2;
62.
63.   if (pipePool <= volume) {
64.     let poolPercent = (pipePool / volume) * 100;
65.     let p1Percent = (pipe1 / pipePool) * 100;
66.     let p2Percent = (pipe2 / pipePool) * 100;
67.
68.     console.log(`The pool is \${Math.trunc(poolPercent)}% full. Pipe 1: \${Math.trunc(p1Percent)}%. Pipe 2: \${Math.trunc(p2Percent)}%.`);
69.
70.   } else if (pipePool > volume) {
71.
72.     let overFlow = pipePool - volume;
73.
74.     console.log(`For \${hours} hours the pool overflows with \${overFlow} liters.`);
75.
76.   }
77.
78. }