Catalan Numbers on Rosetta Code

Post Reply
User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Catalan Numbers on Rosetta Code

Post 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.
smart BASIC Rocks!

- Scott : San Diego, California

Henko
Posts: 822
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Catalan Numbers on Rosetta Code

Post by Henko »

A loose guess: "with memorization" = "recursive" ?

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Catalan Numbers on Rosetta Code

Post 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.
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
Dutchman
Posts: 860
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Catalan Numbers on Rosetta Code

Post by Dutchman »

I understand that with 'memoization' previous results are stored and looked-up if required again.

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Catalan Numbers on Rosetta Code

Post 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.
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
Dutchman
Posts: 860
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Catalan Numbers on Rosetta Code

Post 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? ;)

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Catalan Numbers on Rosetta Code

Post 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.
smart BASIC Rocks!

- Scott : San Diego, California

Post Reply