In a certain pharmaceutical production company, there are two tank reactors operating simultaneously and independent of each other. Each reactor operates by cycling through 4 phases:
At the end of each cycle, a fresh new batch of drugs are being produced. The two reactors produce different drugs, and so the length of time to finish each phase for the two reactors may be different.
However, the company manager wishes to avoid a scenario when the two reactors are both in the cleaning phase at the same time. This is because it takes manpower to clean a tank, and there is not enough manpower to clean two tanks at a time. If we start the filling phase of both reactors at this moment and continue producing batches one after the other without fail, can you determine the earliest time when both tanks require cleaning?
Write a function that takes 4 values, R1, C1, R2, C2, which respectively denotes the amount of time in hours for reacting and cleaning in reactor 1 followed by the amount of time in hours for reacting and cleaning in reactor 2. Since both tanks are of the same size, the filling and emptying phase each takes 1 hour for both of them. You are ensured that all inputs are integers and 1 <= R1, C1, R2, C2 <= 10. Output the earliest hour when the reactors are both undergoing a cleaning phase. You are also ensured that a positive integer answer exists for each test case.
The first two sample test cases below are illustrated in this figure: https://drive.google.com/open?id=1BWnAMQgaiz5OZQe466DiFQ8yTWlm8JRI
Sample test cases:
>> two_reactors(3,2,2,1) ans = 20 >> two_reactors(4,1,2,2) ans = 35 >> two_reactors(1,2,2,2) ans = 5