Page 1 of 1

Catalan Numbers on Rosetta Code

Posted: Thu Dec 29, 2016 8:53 pm
by sarossell
I added code on Rosetta for Catalan Numbers.

http://rosettacode.org/wiki/Catalan_numbers#smart_BASIC

However, I didn't fully grasp the concept of Memoization, so I wasn't able to code for that optional aspect. Anyone up to the challenge? Supposedly, it should be as simple as setting a previously used value in a variable (perhaps in an array) in order to eliminate unnecessary recalculations, but I just couldn't wrap my head around it.

Re: Catalan Numbers on Rosetta Code

Posted: Fri Dec 30, 2016 6:49 am
by Henko
A loose guess: "with memorization" = "recursive" ?

Re: Catalan Numbers on Rosetta Code

Posted: Fri Dec 30, 2016 7:05 am
by sarossell
After looking at some of the other language examples, it appears there is a "recursive" method, a "non-recursive" method and a third method called "recursive with memoization" (whatever the heck that is). The code with memoization includes an extra array or variable for comparison that affects the standard recursive method. I could have translated one of the memoization subroutines into sB but since I didn't full understand it, I didn't want to translate and take credit for something I had no clue what it was doing. The other two were straight forward enough though. The Bracmat language code seems to be the most detailed. But I can;t make heads nor tails of it.

Re: Catalan Numbers on Rosetta Code

Posted: Fri Dec 30, 2016 12:50 pm
by Dutchman
I understand that with 'memoization' previous results are stored and looked-up if required again.

Re: Catalan Numbers on Rosetta Code

Posted: Fri Dec 30, 2016 4:29 pm
by sarossell
Oh. Well in that case, a simple array makes sense after all. It would just store each value as it's generated. That's a lot less complicated than I made it out to be.

Re: Catalan Numbers on Rosetta Code

Posted: Sat Dec 31, 2016 9:41 am
by Dutchman
sarossell wrote: It would just store each value as it's generated. …
Yes but how do you know, in a fast way, which values have been stored? ;)

Re: Catalan Numbers on Rosetta Code

Posted: Sat Dec 31, 2016 5:20 pm
by sarossell
I don't. That's why I didn't code that part. Frankly, I still don't fully grasp what they're looking for.