Post Reply 
OEIS A228297: Need Help to Find Algorithm
09-16-2017, 11:24 PM (This post was last modified: 09-16-2017 11:25 PM by Thomas Okken.)
Post: #6
RE: OEIS A228297: Need Help to Find Algorithm
(09-16-2017 06:46 PM)Gilles59 Wrote:  
Code:
« -> n
  «
    CASE 
      'n<=s+1' THEN 1 END 
      'n<=s+k' THEN n s - END 
      `∑(j=1,k,a(n-j-(s-1)-a(n-j)))`
    END
  »
»
'a' STO

With 0 's' STO , 5 'k' STO
I get correct result for a(1) to a(5)

but a(6) returns "THEN error :undefined name"

What is the problem ?

I'm not familiar with the backquote notation you're using in the default case of your CASE statement (but I don't know RPL very well so that's probably just me). I replaced the backquotes with straight single quotes, and added EVAL to force the expression to be evaluated, and I changed the first case to

'n<=s' THEN 0 END

Then the program works, although, like Gerald's program, it becomes too slow very quickly because of the exponentially increasing run time. You really need to memoize the calculation to keep its run time fast enough, but because of my lack of familiarity with RPL, adapting my C code is left as an exercise to the reader. :-)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: OEIS A228297: Need Help to Find Algorithm - Thomas Okken - 09-16-2017 11:24 PM



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