We have a Spooler S, and a Processor P.

S spools jobs and P processes them.

S can spool 3 jobs per second, while P can process 1 job per second.

We can only have one S but as many Ps as possible.

Since S is three times faster than P, we can assume that for every S start, we need to start 3P. This assumption is WRONG.

If we start S and 3P at the same time, 3P will actually sit idle for a second before they start processing records.

So we need to start 3P after S has spooled the first job. While each of the P is processing the job, S can spool another 3. So every one is happy.

Since we can have as many Ps as we want, we decide to have 9Ps.

We can also assume that we should start 9P after S has completed 3 jobs. WRONG AGAIN

If we go by the above assumption, 9P will process 9 jobs while S fetches 3 jobs.

On the next second, there will be 9P but 3 jobs, so oly 3Ps will be working, 6Ps will be idle, this happens all the time after the first second.

We don’t like idle Ps. So we decided to allow S run 90 times before we start 9P, so that each the Ps have 10 jobs waiting for them before they start.

If you are following me, you know that there will be a point where the Ps will catch up with S.

Questions:

- Determine for 20Million jobs if the Ps will ever catch up with S
- If the answer above is YES, then determine amount of jobs each P needs to be waiting for them before they start so that they can never catch up with s.
- If answer above is NO, then determine how many jobs was needed for the Ps to catch up with S
- Write a program that takes the number of Ps and The total amount of jobs needed as input. Your program should output how many jobs S needs to spool before we start the Ps such that they will never catch up with S.

e.g If we have 18 jobs and 6P, then S needs to spool 9 jobs before we start the Ps.

| seconds | jobs | processed | total rema |

| 1 | 3 | 0 | 3 |

| 2 | 3 | 0 | 6 |

| 3 | 3 | 0 | 9 |

| 4 | 3 | 6 | 6 |

| 5 | 3 | 6 | 3 |

| 6 | 3 | 6 | 3 |

Get answer in the comments đŸ˜‰

Follow @trinisoftinc