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.
Examples
given as input
=> output
.
1
=> 1
1/2
=> 1/2
12/3
=> 1
,2/3
and 1 2/3
(or, equivalently, 5/3
)
2/34
=> 2/3
,4
(cannot be 2/34
because 2 and 34 share a factor of 2)
12/35
=> 12/35
and 1 2/35
and 1
,2/35
and 1
,2/3
,5
12/345/678/9
=> 1
,2/3
,4
,5/6
,7
,8/9
and 5/3
,29/6
,71/9
and 5/3
,45/67
,8/9
and ...
Rules
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 5/3
or 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\$