Boil eggs using hourglasses These are the classical puzzles:

You need to boil eggs for exactly 9 minutes, or else the visiting Duchess will complain, and you will lose your job as head chef.
But you have only 2 Hourglasses, one measures 7 minutes, and the other measures 4 minutes. How can you correctly measure 9 minutes?
(taken from here)

Let's write a program which will produce a solution for any such puzzle.
Input: 3 numbers a, b, x
Here a and b are the durations of the hourglasses, and x is the required time for boiling the eggs. Let's assume the following:

0 &lt; a &lt; b (without loss of generality)
x is not divisible by a or b (to make the problem non-trivial)
x &gt; 0
x is divisible by gcd(a, b) (to ensure a solution exists)

Output: a string which contains commands, such that after executing the commands, we get our eggs boiled for exactly x minutes.
The possible commands are:

'A' - turn hourglass A
'B' - turn hourglass B
'a' - wait until hourglass A runs out
'b' - wait until hourglass B runs out
's' - start boiling the eggs

You may use any single non-whitespace character to encode each command.
You may also use longer strings to encode commands, but then the string of commands must contain separators between each pair of commands.
You may also add a special command &quot;stop boiling the eggs&quot; if it makes implementation easier (naturally, you cannot restart the boiling - the &quot;stop&quot; command is for the case your algorithm cannot restrain itself from printing additional commands after it prints the solution).
You don't need to optimize your string of commands: it may use an inefficient algorithm or contain unnecessary commands, as long as the result is correct.
Test cases:
3, 5, 1 =&gt; ABaAbBsa
4, 7, 9 =&gt; ABaAbBsaAaAa
7, 11, 15 =&gt; ABaAsbBb
69, 105, 42 =&gt; ABaAbBaAaAbBaAbBaAaAbBaAsb
60, 256, 2020 =&gt; ABaAaAaAaAbBaAaAaAaAbBaAsaAaAaAbBaAaAaAaAaAbBaAaAaAaAbBaAaAaAaAbBaAaAaAaAbBaAaAaAaAaAbBaAaAaAaAbBb

Note: these solutions were generated by a script, so they contain completely unnecessary commands.
Python 2, 157 154 108 103 bytes

a,b,c=input()
t=c
while t%a:t+=b
print&quot;&quot;.join(&quot;aA&quot;[i%a*2:]+&quot;bB&quot;[i%b*2:]+&quot;s&quot;[i^t-c:]for i in range(t+1))

Try it online! or Check all test cases!
Input: from STDIN, 3 positive integers a,b,c representing the 2 hourglass times and the time needed for the egg to boil.
Output: print to STDOUT a string of commands following the specification.
Big idea
There exists positive integers \$x,y\$ such that:
$$ax-by=c$$
(Proof in the last section)
Thus, if we continuously flip both hourglasses, the time between when the second hourglass finishes \$y\$ flips and when the first hourglass finishes \$x\$ flips is exactly equal to the time needed to boil the egg.
Code overview
t keeps track of \$by+c\$. We increment \$y\$ until \$\frac{by+c}{a}\$ is an integer.
When a valid value of t is found, t will be the time needed to flip the first hourglass \$x\$ times, and also the time when the egg should be done. t-c is the time when the second hourglass finishes \$y\$ flips, and also the time when the egg should start to be boiled.
The command string is created by increasing the time i, and insert &quot;aA&quot; or &quot;bB&quot; every time \$a\$ or \$b\$ divides the current time. &quot;s&quot; is inserted when the time is t-c.
Proof of the existence of \$x\$ and \$y\$.
Since \$c\$ is a multiple of \$gcd(a,b)\$, Bézout's identity claims that there exists integers \$k_1, k_2\$ (which can be negative) such that:
$$k_1a-k_2b=c$$
Since \$ba - ab = 0\$, we can increase \$k_1\$ and \$k_2\$ by \$b\$ and \$a\$ without changing the result:
$$(k_1+b)a-(k_2+a)b=c$$
Thus, we can keep increasing \$k_1\$ and \$k_2\$ until they are both positive.