This puzzle is based on [this Math.SE post][1]. Assume I have some number of black shirts and some number of white shirts, both at least 1. Both colors of shirt have a non-zero durability. All shirts of a given color start with the same durability. Every day, I pick out a clean shirt to wear, and it becomes dirty. Once I run out of all clean black shirts or all clean white shirts, I wash all my dirty shirts of both colors and start over. Clean shirts do not get washed. Whenever a shirt gets washed, its durability goes down by one. Immediately after washing, if the durability of a shirt reaches 0, it must be thrown out. When picking which shirt to wear of a particular color, I always choose a shirt with the highest durability of that color to ensure even wear and tear among shirts. Challenge: = Take in a sequence of two characters of arbitrary length (eg. b b b w b w w b...) representing my choice of shirt to wear on that day. Continue execution until either my last black shirt or my last white shirt is thrown out. Once this occurs, stop consuming input and halt execution immediately. Note that the program must not consume any more input than is required before halting. Inputs: - Number of black shirts, number of white shirts, durability of black shirts, durability of white shirts, and an arbitrary number of two single characters, your choice (eg. b and w) Output - None. The program must simply halt when the last shirt of either color is thrown away. Test cases - 1 1 1 1 b 1 999 1 999 b 1 999 1 999 w w w w w w w w b 2 999 1 999 b w w w b 2 999 2 999 b w w w b w b w w w b 5 3 6 1 w w w w w b b b b b b b b b b b b b b w General rules: = - This is [tag:code-golf], so shortest answer in bytes wins. - Default input rules apply for the first four arguments. For the arbitrarily long input sequence after the first four arguments, input must come from a source which can provide input one character or byte at a time, of theoretically infinite length, such as STDIN or some other stream. [1]: https://math.stackexchange.com/q/3261079/3392 [2]: https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default