8
0
Winner: Ian D. Scott's answer, by one byte (48 bytes)! Superb!
Your program must accept input from a fraction that can be simplified, then simplify it.
Rules:
- If the fraction is already in its most simplified form, you must inform the user
- No built-in functions to do this
- The user must type the number at some point, however the method the program reads it does not matter. It can be with stdin, console.readline, etc. As long as the user types
9/18
(for example) at some point, it is valid - Output must be done with stdout, console.writeline, etc...
- The fraction will be put in as
x/y
, and must output asa/b
- The fraction must output the most simplified form. For example, 8/12 -> 6/9 is not valid, the only valid solution is 2/3.
- This contest ends on August 9th, 2014 (7 days from posting)
- This is a code-golf question, so the shortest code wins
3What do you mean by "If the fraction is already in its most simplified form, you must inform the user"? Should there be a specific message apart from just returning the input? If so, I don't the the accepted answer satisfies this. – Martin Ender – 2015-04-15T17:52:40.143
I honestly think Python shouldn't use the fractions.py module for this. – mbomb007 – 2015-04-15T19:05:14.767
1How should we inform the user? – bebe – 2014-08-02T07:13:18.220
Stdout, console.writeline, etc. – Jon – 2014-08-02T07:14:00.307
7This is really quite a trivial problem. All you do is divide by the gcd (a function that is often built in but would not be hard to write). – Calvin's Hobbies – 2014-08-02T07:41:43.210
1@Calvin'sHobbies Yeah, the problem itself is trivial. Doing it in the shortest amount of code isn't as easy. – Jon – 2014-08-02T17:47:27.780