Post Reply 
What is the best BASIC Pocket Computer
04-16-2014, 08:23 PM
Post: #74
RE: What is the best BASIC Pocket Computer
(04-16-2014 12:47 AM)Dave Britten Wrote:  Here you go, prime factors in GW-BASIC. I haven't done any real performance tuning, apart from selecting an algorithm that's more efficient than "2 plus all the odd numbers".

OK there where only minor changes to the code necessary. Deleted line 5, as UBASIC calculates long variables with a size of 542 words (whatever that is Smile) and timing (line 15 and 920) has a different syntax.

Code:
   10   input "X=";X
   15   clr time
   20   M=int(sqrt(X))
   30   F=0
   40   data 2,1,2,2
   50   for I=1 to 4
   60   read S:gosub 500
   70   next I
  100   if X<=1 then 900
  105   data 4,2,4,2,4,6,2,6
  110   for I=1 to 8
  120   read S:gosub 500
  130   next I
  140   restore 105
  190   if F>M then F=X:S=0:gosub 500
  200   goto 100
  500   F=F+S
  510   if X/F<>int(X/F) then return
  520   X=X/F
  530   M=int(sqrt(X))
  540   print F;
  550   goto 510
  900   print
  910   print "Execution time: ";
  920   print time1000/1000;:print "s"
  930   end

Your example of 167699497 is calculated in about 2.4 seconds

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-16-2014 08:23 PM



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