I'm building a giant lego robot and I need to generate some particular gear ratios using a set of gears. I have lots of gears with the common lego gear sizes: 8, 16, 24, or 40 teeth. Write a program I can use where I input a gearing ratio and the program tells me what combination of gears I should use to get the requested ratio.
The input ratio will be specified on standard input (or your language's equivalent) with two integers separated by a colon. A ratio of
a:b means that the output shaft should turn
a/b times as fast as the input shaft.
The output to standard output should be a single line containing a space-separated list of gear ratios, in the form of
x is the size of the gear on the input shaft and
y is the size of the gear on the output shaft. You must use the minimum possible number of gears for the given ratio. Each
y must be one of
1:5 -> 8:40 10:1 -> 40:8 16:8 9:4 -> 24:16 24:16 7:1 -> IMPOSSIBLE 7:7 -> 6:15 -> 16:40
If the desired gear ratio is impossible, print "IMPOSSIBLE". If no gears are required, print the empty string.
This is code golf, shortest answer wins.