Post Reply 
Repeating Decimals
01-19-2018, 03:58 AM (This post was last modified: 01-23-2018 02:31 AM by Joe Horn.)
Post: #7
RE: Repeating Decimals
Oh my goodness, it hit me today that the whole headache of finding the multiplicative order of 10 (mod X) can be entirely avoided! All we have to do is:
  • Find how many digits DON'T repeat (easily done, as explained above).
  • Using infinite division, output that many digits.
  • At that point, save the current remainder.
  • Output more digits using infinite division, but as soon as the remainder saved in the previous step reoccurs, STOP.
That's all it takes! Example using RPL (because I think in RPL):

123/208

EDIT: STEP ZERO: Fully reduce the fraction, if your machine doesn't automatically do that for you (like RPL machines do). [Thanks to tgray for catching this oversight!]

First, find how many digits after the decimal point don't repeat:
208 = 2^4 * 5^0 * 13, and MAX(4,0) is 4, so any integer divided by 208 will have 4 digits after the decimal point which don't repeat.

Secondly, find the integer part of the answer:
123 208 IDIV2 --> 0 123 <-- Integer part of answer (on level 2 of the stack; the remainder 123 is on level 1 of the stack).

Thirdly, print that 0 and a decimal point here.

Fourthly, do 10 * 208 IDIV2 four times to get the 4 digits which don't repeat, printing each digit as it's calculated:
10 * 208 IDIV2 --> 5 190 <-- Begin non-repeating part
10 * 208 IDIV2 --> 9 28
10 * 208 IDIV2 --> 1 72
10 * 208 IDIV2 --> 3 96 <-- End repeating part. Save that remainder.

Fifthly, print the underscore character "_" to separate the non-repeating digits from the repeating digits.

Sixthly and finally, repeat 10 * 208 IDIV2, printing each digit as it's calculated, until that saved remainder reappears.
10 * 208 IDIV2 --> 4 128
10 * 208 IDIV2 --> 6 32
10 * 208 IDIV2 --> 1 112
10 * 208 IDIV2 --> 5 80
10 * 208 IDIV2 --> 3 176
10 * 208 IDIV2 --> 8 96 <-- There it is! STOP. Done.

So 123/208 = 0.5913_461538 (using the underscore to mean "here begin the repeating digits").

Holy smokes, that's EASY to program in RPL! No "multiplicative order" routine is necessary! Writing it in HP PPL is left as an exercise for the student. Wink

<0|ΙΈ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Repeating Decimals - lrdheat - 01-13-2018, 12:22 AM
RE: Repeating Decimals - lrdheat - 01-13-2018, 12:23 AM
RE: Repeating Decimals - salvomic - 01-13-2018, 10:06 AM
RE: Repeating Decimals - lrdheat - 01-13-2018, 06:09 PM
RE: Repeating Decimals - Joe Horn - 01-17-2018, 06:20 AM
RE: Repeating Decimals - lrdheat - 01-18-2018, 05:46 AM
RE: Repeating Decimals - Joe Horn - 01-19-2018 03:58 AM
RE: Repeating Decimals - lrdheat - 01-19-2018, 03:11 PM
RE: Repeating Decimals - Joe Horn - 01-20-2018, 06:02 AM
RE: Repeating Decimals - StephenG1CMZ - 01-20-2018, 09:08 AM
RE: Repeating Decimals - StephenG1CMZ - 01-21-2018, 11:34 AM
RE: Repeating Decimals - StephenG1CMZ - 01-21-2018, 10:22 PM
RE: Repeating Decimals - Joe Horn - 01-21-2018, 10:41 PM
RE: Repeating Decimals - StephenG1CMZ - 01-21-2018, 10:58 PM
RE: Repeating Decimals - Joe Horn - 01-22-2018, 01:35 AM
RE: Repeating Decimals - tgray - 01-23-2018, 01:46 AM
RE: Repeating Decimals - Joe Horn - 01-23-2018, 02:18 AM
RE: Repeating Decimals - tgray - 01-23-2018, 02:24 AM
RE: Repeating Decimals - lrdheat - 01-27-2018, 09:53 PM
RE: Repeating Decimals - StephenG1CMZ - 02-05-2018, 11:34 PM
RE: Repeating Decimals - StephenG1CMZ - 02-06-2018, 11:34 PM



User(s) browsing this thread: 1 Guest(s)