Periods of Reciprocals of Integers
|
08-06-2018, 03:37 AM
Post: #4
|
|||
|
|||
RE: Periods of Reciprocals of Integers
Meanwhile I've extracted the redundant code into a "function" reduce:
Code: LBL "PERIOD" If you want to also display the digits you can include the following lines: Code: RCL X ; 10*p 10*p 1 However the result isn't correct for values divisible by 2 or 5. (08-06-2018 12:59 AM)Albert Chan Wrote: A slight optimization is to check if p==n-1 too, and return k+k Fair point. But we'd still have to run to \(2k\) if we wanted to display the digits. (12-30-2017 02:19 PM)Macumazahn Wrote: The challenge here is that the program must keep track of all the remainders it has seen, so that it can detect the first repetition. You could also use Floyd's cycle detection algorithm or a variant thereof. They use only a constant number of memory cells. Cheers Thomas |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Periods of Reciprocals of Integers - Macumazahn - 12-30-2017, 02:19 PM
RE: Periods of Reciprocals of Integers - Thomas Klemm - 08-05-2018, 08:49 PM
RE: Periods of Reciprocals of Integers - Albert Chan - 08-06-2018, 12:59 AM
RE: Periods of Reciprocals of Integers - Thomas Klemm - 08-06-2018 03:37 AM
RE: Periods of Reciprocals of Integers - Albert Chan - 08-06-2018, 02:05 PM
RE: Periods of Reciprocals of Integers - Thomas Klemm - 08-06-2018, 05:30 PM
RE: Periods of Reciprocals of Integers - Albert Chan - 08-06-2018, 07:41 PM
|
User(s) browsing this thread: 4 Guest(s)