HP Forums

Full Version: Request for "Decimal Period of 1/X in Base Y" program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
If you want to do it for any base, instead of removing 2s & 5s, remove any factors of that base & change the 10 near the end for the required base - I believe that will solve it.

It might be an idea to change title of thread so others can find solution to length of period problem.
(03-01-2015 10:17 PM)Gerald H Wrote: [ -> ]If you want to do it for any base, instead of removing 2s & 5s, remove any factors of that base & change the 10 near the end for the required base - I believe that will solve it.

Will try that. I hope it's a valid method, because that's the method used by my URPL program, but it's much slower than yours.

Quote:It might be an idea to change title of thread so others can find solution to length of period problem.

Good idea. Done.
(03-01-2015 05:40 PM)Joe Horn Wrote: [ -> ]
(02-27-2015 09:57 AM)Gerald H Wrote: [ -> ]IF you're only interested in integer values for X & Y, this 50G prog does the job: ...

Z0_

...

The 9th line of your program won't compile using the built-in tools. What is Z0_?

EDIT: Never mind, I figured out it means ZINT 0. What assembler is that for?

Sorry, it's a custom EXTABLE for ROM 2.10-7.

Yes, Z0_ is ZINT 0.
(03-02-2015 07:09 AM)Joe Horn Wrote: [ -> ]
(03-01-2015 10:17 PM)Gerald H Wrote: [ -> ]If you want to do it for any base, instead of removing 2s & 5s, remove any factors of that base & change the 10 near the end for the required base - I believe that will solve it.

Will try that. I hope it's a valid method, because that's the method used by my URPL program, but it's much slower than yours.

Quote:It might be an idea to change title of thread so others can find solution to length of period problem.

Good idea. Done.

OK, how about this prog:

«
WHILE DUP PICK3 GCD DUP 1 >
REPEAT /
END DROP SWAP ORD
»
(02-27-2015 08:49 AM)Thomas Ritschel Wrote: [ -> ]Here is a simple non-CAS variant:
Code:
EXPORT MultiplicativeOrder(a,base)
BEGIN
  LOCAL k:=0;
  LOCAL res:=1;
  REPEAT
    res:=res*base;
    k:=k+1;
    res:=res MOD a;
  UNTIL res==1;
  RETURN(k);
END;

I am using this procedure to analyze repeating decimals/recurring decimals here:
http://www.hpmuseum.org/forum/thread-9986.html
I now have an optimised version of MultiplicativeOrder for base 10 on the Prime here:
http://www.hpmuseum.org/forum/thread-9986.html
(03-01-2015 06:17 PM)Joe Horn (post 18) Wrote: [ -> ]Uh oh. Running it after 12 ENTER 23 yields 22, but the correct answer for the period of 1/23 in base 12
(as returned by my URPL program above) is 11, as can be seen by actually writing 1/23 in base 12:

0.06316948421 06316948421 06316948421 06316948421 ...

Am I misunderstanding something here?

The code for order(a,n) were wrong. order(12,23) = 11, matching repeating decimals period.

GCD does 2 duties: satisfy order() co-prime arguments requirement, and to track where to put the "decimal" point.

Example, 1/360 to base 12

12/360 = 1/30
12/30 = 2/5
Stop further scaling since gcd(12,5) = 1

order(12,5) = 4
12^4-1 = 20735

2/5 = (20735*2/5) / 20735 = 8294/20735 = 4972/BBBB (base 12)

1/360 = 0.00 \(\overline{4972}\) (base 12)
Pages: 1 2
Reference URL's