+ 21

[🏆 CHALLENGE 🏆] REPEATING DIGITS 🔢1⃣2⃣

Challenge #5 Let's do some math this time. The challenge is to make a code which outputs the number whoose 1/n will have the maximum no of repeating decimals till the number inputted. Eg. Input->10 Output-> 7, It has 6 repeating digits. 1/7=0.(142857) Note : 1/7 =0.142857142857... so, 142857 repeats, which has 6 digits so the output is 6. 1/7 has move no of repeating decimals than any 1/n when n is less than 10. EDIT: DON'T TRUST FLOAT CALCULATIONS. Good luck 👍 Happy coding. At least try to participate.

10th Jan 2018, 11:18 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
11 Answers
+ 4
it turns out that the highest period until a give point is always a prime less than n with a period length of p-1.for more information see this link https://oeis.org/A051626 https://code.sololearn.com/cX2Fa4zwiE60/?ref=app
11th Jan 2018, 10:18 PM
Chief Commander
Chief Commander - avatar
+ 22
i also think that there is some need to restrict the domain //will see this later now👋👋
10th Jan 2018, 1:33 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
10th Jan 2018, 10:08 PM
LukArToDo
LukArToDo - avatar
+ 14
see 1/1=1(no repeat) 1/2=0.5(no repeat) 1/3=0.33333(1 digit repeating) 1/4=0.25 1/5=0.2 1/6=0.166666(1 digit) 1/7=0.142857142857142857(6 digits ) 1/8=0.125 1/9=0.1111(1 digit) 1/10=0.1 So, 1/7 has the most no of repeating digits. So the answer is 7.
10th Jan 2018, 2:24 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 13
Here's again 😁 Made in accordance with Swapnil's suggestions. It was much harder than I expected 😓 Thanks for the great challenge 😉 https://code.sololearn.com/c4DS7g9HjMGq/?ref=app
11th Jan 2018, 7:33 PM
LukArToDo
LukArToDo - avatar
+ 5
Cool, may try if I have time. (1/97, anyone?)
10th Jan 2018, 1:09 PM
blackcat1111
blackcat1111 - avatar
+ 5
oh! my god!! thats some challenge!!!
12th Jan 2018, 7:58 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 4
@Swapnil Srivastava Do I correctly understand that I have for the input 10 to check every previous division so k ele [1....10] = 1/k 1/1, 1/2, 1/3, .... 1/10? right? So the next question is how to proceed with periodic values because obviously they would have the most repeating digits if not defined otherwise (max-length/2 - 1). Or are they excluded by definition of your challenge :). So we have to restrict the example a little bit.
10th Jan 2018, 1:34 PM
thex
thex - avatar
+ 3
Assumed that periodic is not allowed. By my definition if a value occurs more than once behind each other in the accordance => skip. Here my solution written in Java: https://code.sololearn.com/cySky6n3EB9n/#java -------------- Ad: I decide to write a second version which also finds multiple maxes: https://code.sololearn.com/cWcXtaa1GHbw/#java
10th Jan 2018, 3:34 PM
thex
thex - avatar
+ 2
This is my try, sorry for delay. It was hard but teached me a lot about accuracy of divisions in python, thanks @Swapnil Srivastava for the challenge. Anyway my solution isn't short but is complete and it calculate every periodic part of every razional number, simple or mixed. https://code.sololearn.com/c5KYOua25Jdx/#py
15th Jan 2018, 1:09 AM
Jamil Mameri
Jamil Mameri - avatar
+ 1
It will calculate only from 1 to 42 Because there are many loop and long data type limitations. But very right answer ))) https://code.sololearn.com/c1l9DXK5Obi0/?ref=app
11th Jan 2018, 8:55 PM
abdulazizumarovich
abdulazizumarovich - avatar