# Problem 45402. Find an overlap in the cleaning schedule of two tank reactors

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:
1. Filling phase - The empty reactor is filled with raw materials.
2. Reacting phase - The filled reactor is heated to start the chemical reaction.
3. Emptying phase - The reaction ends and the tank is emptied of all contents.
4. Cleaning phase - The emptied reactor must be cleaned to prepare for the next batch.
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 the following figure.
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

### Solution Stats

59.05% Correct | 40.95% Incorrect
Last Solution submitted on Jul 22, 2024

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!