⏲️
Broken Clocks
Week 24
It is said a broken clock is correct twice a day - for this challenge, you have 1 known correct clock/stopwatch (you can consider them being mm:ss format) and 2 or 3 incorrect ones that are running at slightly different speeds. You want to determine the time taken after they have started until they all simultaneously display "00" on the second display
For example, below we see our correct clock - labelled "*" below - at 1 minute intervals along with clock A that shows 30 seconds have passed for every real minute and clock B that says 45 seconds have passed for every real minute
| Minutes | ||
|---|---|---|
| * | A | B |
| 1:00 | 0:30 | 0:45 |
| 2:00 | 1:00 | 1:30 |
| 3:00 | 1:30 | 2:15 |
| 4:00 | 2:00 | 3:00 |
We can see after 4 minutes (or 240 seconds) of real time, all clocks are now displaying a whole minute value
For your program, the goal is to find the 2 and 3 incorrect clock combinations (remember, since there is also the correct clock, when we say 2 incorrect clocks, that means 3 clocks total (i.e. 1 correct, 2 incorrect) - likewise, 3 incorrect clocks = 4 clocks total) that take the longest time to synchronise to a whole minute value with the known correct clock
As an example of 3 incorrect clocks, if the correct clock is at 600 seconds, clock A is at 480 seconds, clock B is at 900 seconds and clock C is at 720 seconds, then this is considered synchronised, since all clocks would be showing a whole number of minutes (8, 10, 15 and 12 respectively)
For the program's input, you can limit clock timing speeds to be integers in the range 1 to 60 inclusive - i.e. a clock could show 1 second for every real minute passed, 2 seconds for every real minute passed etc...but not 1.5 seconds or 61 seconds etc
The data in the example below is deliberately wrong (so don't go testing/comparing it with yours) to avoid giving hints for the answer, yet shows the expected answer format - note the following:
- Combinations should be unique - i.e. 17 37 is the equivalent to 37 17, likewise 1 2 3 is the same as 3 1 2, so only one should be displayed & counted - the site will accept any order
- Each value in the combination should also be unique - e.g. 1 1 2 would be invalid, since the number 1 appears twice
- A count of the unique combinations that took the maximum time to sync to a whole minute value and that number of seconds should be displayed - for example, if 3 different combinations took 1800 seconds to sync to a whole minute, then that information should be output in the format below
- Don't worry about plurality - both "combinations" and "combination" will be accepted
- The max number of seconds for both 2 and 3 clock combinations should be shown
Remember, that data above is deliberately wrong to avoid giving away any hints/patterns - it just shows the expected format. In this example, if we look at the first row, it's saying clock A running at 13 seconds per minute and clock B running at 41 seconds per minute took 1200s to both synchronise with the correct clock to a whole minute value. Your goal is to find all combinations that take the longest to sync to a whole minute for both 2 and 3 clock combinations and paste that result below:
Hints
Hints will be released at the start of each of the following days - e.g. the start of day 3 is 48 hours after the challenge starts
| Release Day | Hint |
|---|---|
| 2 | You will want to generate all the unique 2 and 3 offset clock combinations |
| 3 | Remember, you only want to generate each clock combination once - a simple way to do this would be to generate the clock combinations in where each clock (a, b and for 3 clocks, c) is in ascending order - e.g. you would generate 1 2 3, but not any other combination like 3 2 1 |
| 4 | You could do this with 2 loops (1 level of nesting) for the 2 clocks and 3 loops (2 levels of nesting) for the 3 clocks - you could loop 1 to 60 for each clock, then have an if statement to only check the clocks if a > b and b > c for example - alternatively, a more elegant & efficient solution would be setting b's start loop value to 1 greater than a's value and likewise c's starting value to 1 greater than b |
| 5 | To check if the clocks are on a whole minute, you will want to use modulus - think what number you will need to mod by |
| 6 | If each of the clocks mod 60 = 0, then the condition has been met |
| 7 | You will need to store the maximum time and a dynamic array containing all the combinations that take that maximum time to synchornise to a whole minute - after looping through all combinations, you will want to output each combination in this maximum time array |