Post Reply 
HP 38G: Better than Prime for some Sequences using the built in Sequence App
03-07-2015, 12:25 PM (This post was last modified: 03-07-2015 12:26 PM by Gerald H.)
Post: #30
RE: HP 38G: Better than Prime for some Sequences using the built in Sequence App
(03-07-2015 11:58 AM)BruceH Wrote:  
(03-07-2015 11:39 AM)Marcus von Cube Wrote:  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.

Excellent stuff. Input 9999 & answer returned in 45 sec. A student of mine confirms 5372 is the correct answer.

Once again bravo, BruceH.

Concerning revenge, 'tis sweet, & so is learning something new.

Edit: Title of thread updated.
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 some Sequences using the built in Sequence App - Gerald H - 03-07-2015 12:25 PM



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