9
2
Your challenge is to convert a fraction into its continued fraction form.
Input: The fraction may be input in any format, including (but not restricted to)
- string: "7/16"
- list: {7, 16}, (7, 16), [7, 16]
- simple ordered pair: 7 16
- function: f[7,16]
Output: A continued fraction, in 2D, with horizontal fraction bars separating numerator from denominator. Only continued fractions with numerators equal to 1 are valid. It is not necessary to make the font size vary according to depth. A leading zero (for proper fractions) is optional.
Depth: Your code must be able to display at least 8 levels of depth.
Winning criterion: Shortest code wins. You must include several test cases showing input and output.
Test Examples (Input followed by output)
5/4
5/3
5/7
9/16
89/150
what's the criteria for how deep you must go? for example, why can't we just do
0 + 89 / 250
for the last one? – Doorknob – 2013-12-03T22:35:41.293I was presupposing that the only acceptable numerator was 1. I'll add that. – DavidC – 2013-12-03T22:37:13.160
ah okay, don't have much of a math background :) Wikipedia helped. How about languages that can't display things in this format? Is it okay if we do something like
0 + 1 / (1 + 1 / (1 + 1 / (2 + 1 / (3 + 1 / (1 + 1 / (1 + 1 / (2)))))))
? What about without the parenthesis? Or if we just display the blue numbers, like0 1 1 2 5 1 1 2
? – Doorknob – 2013-12-03T22:40:17.3031Your notation appears to be mathematically correct. But the main point of the challenge is to figure out a way to display the fraction in column and row format (which I referred to above loosely as 2D). – DavidC – 2013-12-03T23:02:46.960