Problem 2162. Let's get back to school: create mixed numbered fraction
A fractional number can be represented as mixed number.
A "mixed number" consists of an integer followed by a proper fraction and "proper fraction" is a fraction with the numerator smaller than the denominator.
e.g. if given fraction is, 1.33 then, it can be represented as 1 (1/3), meaning, (1*3+1)/3 = 4/3 = 1.33
The task is to convert the given fractional number into a mixed number and return the 3 digits as an array of length 3. For making it easy and to output unique solution, the integer should always be 1 and the remaining fraction need not be a "proper fraction". (so for input 1.33, output will be [1 1 3], for input 1.66, output will be [1 2 3] )
Solution Stats
Problem Comments
-
4 Comments
You said: "a fraction with the numerator smaller than the denominator", so test cases 3 to 6 are not consistent to this sentence. :-/
The Test Suite and problem statement are now consistent with each other, but I don't think anybody learned at school to write 1 9/7, rather than 2 2/7.
Other issues with the Test Suite (or problem statement): FIRSTLY, 1 2/3 is equal to 1 4/6, or 1 6/9, et cetera, but only the first option is accepted in the Test Suite. SECONDLY, the rounding used in the inputs means that more correct answers would be e.g. 1.33 = 1 33/100. LASTLY, there is no possible way to know that 2.00 should be represented as 1 5/5, rather than 1 4/4, or 1 3/3 et cetera.
We should not round real numbers if we want their rational representation. The real number 1.33 is not represented as 1+1/3, but rather as 1+33/100([1 33 100]). While rounding values, I was able to find a kind of ugly solution for this problem. However, the last test case does not make sense. The problem should require the minimum rational number to avoid multiple answers. Therefore, an integer number such as 2 should be represented as [1,1,1], 3 should be [1,2,1] and so on. Please, fix your test suite, it is a good problem.
Solution Comments
Show commentsProblem Recent Solvers23
Suggested Problems
-
Swap the first and last columns
20438 Solvers
-
2262 Solvers
-
331 Solvers
-
579 Solvers
-
394 Solvers
More from this Author25
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!