+ 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.
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
+ 7
I have edited the question.
+ 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 ?
+ 5
Oh yes.
+ 5
ok
+ 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
+ 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....
+ 4
oh! i'm sorry for the unclear question. :D
+ 4
@sayan you can also simplify the fraction! :D
+ 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
+ 3
+ 3
@VcC you are correct. But I think it would be better like 123.456223{223}.
+ 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....
+ 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
+ 2
jonathan
123.456(223)
is enough to understand...
its u who do the rest manupulation..
+ 2
Ok.
+ 2
Ah. I'm cheating ๐
I used Rational class.
https://code.sololearn.com/cCTuOb5HrAqi/?ref=app
+ 1
I think you mean 'non-terminating'.
+ 1
Haha. But youvdo not simplify the fraction
+ 1
thats good...
u saw my code??