Post Reply 
What is the best BASIC Pocket Computer
04-18-2014, 09:12 PM
Post: #86
RE: What is the best BASIC Pocket Computer
(04-16-2014 08:23 PM)Guenter Schink Wrote:  Your example of 167699497 is calculated in about 2.4 seconds

Günter

Now I have transformed the code into a structured form, no "GOTOs" any more Smile. Then I use some special operations of UBASIC. But the algorithm is the same still.
Code:
 100   input "X=";X
  110   clr time
  120   M=int(sqrt(X))
  130   F=0
  140   data 2,1,2,2
  145    ' take care of divisors 2-7
  150   for I=1 to 4
  160   read S:gosub *Divide
  170   next I
  180   data 4,2,4,2,4,6,2,6
  185    'Now calculate with numbers >7 omitting all that can be divided by 2,3 and 5
  190   while X>1
  200    for I=1 to 8
  210    read S
  220    gosub *Divide
  230    next I
  240    restore 180
  250    if F>M then
  260    :    F=X
  270    :    S=0
  280    :    gosub *Divide
  290    endif
  300   wend
  310   ET=time1000/1000     'time1000 gives milliseconds after last "clr time"
  320   print:print "Execution Time: "
  330   print ET;
  340   end
  345   'Now start factoring
  350   *Divide
  360   F+=S                'this is shorter and faster for F=F+S
  370   while not X@F        'while there is no remainder
  380       X\=F            'this is short for x=x\f where "\" denotes integer division
  390        M=int(sqrt(X))
  400        print F;
  410   wend
  420   return

This program needs 1.53 sec for 167699497 on the 200LX.

Günter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: What is the best BASIC Pocket Computer - Guenter Schink - 04-18-2014 09:12 PM



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