+ 10

[๐Ÿ† Challenge ๐Ÿ†]:: Non-Terminating decimal converter๐Ÿ”ข๐Ÿ†๐Ÿšจ๐Ÿ’กโš ๐ŸŽฎ

Write a code to accept a non-terminating decimal followed by an underscore as the input and simplify it in the form of a fraction. Like 0.333333... is a non-terminating decimal with its simplified fraction being 1/3. Eg: Input-> 0.(3)_ Output->1/3 Input->0.(142857)_ Output-> 1/7 Input-> 0.(9)_ Output-> 1 Input-> 0.(2)_ Output-> 2/9 Hope you understood the question.

24th Oct 2017, 10:20 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
25 Answers
+ 10
Here's my C# implementation! โœŒ Sorry for late to the party! To be honest I feel my code is extremely lengthy compared to the submissions here but I've done my best. Again, thanks for another interesting Maths challenge! Enjoy~ โค https://code.sololearn.com/cUhmHfZOjLwr/?ref=app
28th Oct 2017, 3:59 PM
Zephyr Koo
Zephyr Koo - avatar
+ 7
I have edited the question.
24th Oct 2017, 2:02 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 6
@sayan yes I saw but who will simply the fraction? eg- I input 0.(142857)_ then it outputs 142857/999999 but, who will further simplify it ? i.e., 1/7 ?
24th Oct 2017, 2:12 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 5
Oh yes.
24th Oct 2017, 11:09 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 5
ok
24th Oct 2017, 2:01 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 5
This challenge gave me a headache. I thought is was my code but I found out the problem was the floating point calculations.๐Ÿ˜ฅ๐Ÿ˜ง๐Ÿ˜ต๐Ÿ˜ต But I learned a lot. Anyways, here is my try. Please check for any errors. Thanks for the challenge.๐Ÿ˜Š PS: I think the underscore is unnecessary. https://code.sololearn.com/WdyBVan0wzst/?ref=app
25th Oct 2017, 3:37 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 4
@VcC correct but didn't properly understand the question. Your program takes 0.142857_ as 0.1428577777777.... while it should take it as 0.142857142858142857142857....
24th Oct 2017, 12:46 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 4
oh! i'm sorry for the unclear question. :D
24th Oct 2017, 1:58 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 4
@sayan you can also simplify the fraction! :D
24th Oct 2017, 1:59 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 4
Swappi, normally I should not use fractions. But I only used gcd. That was ok for me. So here is Python: https://code.sololearn.com/cg6rvMbEqw03
27th Oct 2017, 11:58 AM
Oma Falk
Oma Falk - avatar
24th Oct 2017, 12:19 PM
VcC
VcC - avatar
+ 3
@VcC you are correct. But I think it would be better like 123.456223{223}.
24th Oct 2017, 1:31 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
@sayan is right. Problem statement unclear. You need a different way to input repetition like 123.456{223} to separate repeating and non repeating numbers....
24th Oct 2017, 1:06 PM
VcC
VcC - avatar
+ 2
AND EXACTLY I DID THAT @ VCC @ SWAPNIL input : 45.67(89) means 45.678989898989.... 7.000(5) means 7.00055555555555.... got it?????? now here comes the legendary ONE LINER https://code.sololearn.com/cU3xJ7EPDCjT/?ref=app
24th Oct 2017, 1:25 PM
sayan chandra
sayan chandra - avatar
+ 2
jonathan 123.456(223) is enough to understand... its u who do the rest manupulation..
24th Oct 2017, 1:38 PM
sayan chandra
sayan chandra - avatar
+ 2
Ok.
24th Oct 2017, 1:55 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
Ah. I'm cheating ๐Ÿ˜œ I used Rational class. https://code.sololearn.com/cCTuOb5HrAqi/?ref=app
25th Oct 2017, 2:10 PM
Hiroki Masuda
Hiroki Masuda - avatar
+ 1
I think you mean 'non-terminating'.
24th Oct 2017, 11:03 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
Haha. But youvdo not simplify the fraction
24th Oct 2017, 1:28 PM
VcC
VcC - avatar
+ 1
thats good... u saw my code??
24th Oct 2017, 2:05 PM
sayan chandra
sayan chandra - avatar