Post Reply 
HP 38G: Better than Prime for some Sequences using the built in Sequence App
03-07-2015, 11:58 AM (This post was last modified: 03-07-2015 12:01 PM by BruceH.)
Post: #27
RE: HP 38G: Better than Prime for Sequences
(03-07-2015 11:39 AM)Marcus von Cube Wrote:  
(03-07-2015 11:29 AM)Gerald H Wrote:  On the 38G 99 takes 122sec

& 40gs takes 39 sec.

The performance of the Prime is disappointing.

There is a reason: The implementation with the TT routine evaluates each element of the sequence from scratch while the sequence app recurses on the previous results. Maybe storing the previous values in a list instead of performing a recursive call will give better run times. This of course makes the calls to TT not independent from each other.

and I did say it was my 'revenge' :-)

Here is a list optimised version that is much quicker. Make sure you delete the contents of L1 before the first run. The results go into L1 and can be viewed from the List view (shift + 7).
Code:
EXPORT TT(n)
BEGIN
  LOCAL k, s;
  s := SIZE(L1);
  IF s <= 2 THEN
    L1 := {1,1}; s:= 2;
  END;
  IF s < n THEN
    FOR k FROM s+1 TO n DO
      L1(k) := L1(L1(k-1))+L1(k-L1(k-1));
    END
  END;
  RETURN L1(n);
END;
NB: Sometimes you get "Error:invalid input" on the first run. Just run it again. You can still use it from the sequence app if you wish, just assign U1(3) := TT(N) as before.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 38G: Better than Prime for Sequences - BruceH - 03-07-2015 11:58 AM



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