Help! I printed a bunch of rational numbers with no spaces or other delimiters other than the
/ in the fractions. There is, however, good news! All the numbers are positive. There are no improper fractions, every numerator is less than its denominator and any integers are represented directly, not as fractions. Any non-integers greater than 1 are represented as an integer followed by a fraction. Every fraction is reduced to lowest terms, no numerator and denominator have any common factors other than 1.
Using this information, and given a string that I've printed, I need you to tell me what the original numbers could have been. If there are multiple possibilities, I want to know all of them.
1 2/3 (or, equivalently,
4 (cannot be
2/34 because 2 and 34 share a factor of 2)
1 2/35 and
8/9 and ...
You can assume there is at least one valid way to delimit the input.
Your results can contain improper or mixed fractions, you can represent 5/3 as
1 2/3. You can use any kind of delimiters, as long as each type of delimiter (start and end of a list, between numbers, between integer and fraction in a mixed fraction, between numerator and denominator in a fraction) is unique and consistent. You can take input from stdin, or function parameters, or command line options. You can print your results, or return them from a function, or even just leave them in a variable.
/s. I think this addition is confusing and poorly explained. Not to mention I think the challenge is more interesting without it. \$\endgroup\$