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.
Catalan Numbers on Rosetta Code
- sarossell
- Posts: 195
- Joined: Sat Nov 05, 2016 6:31 pm
- My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
- Flag:
- Contact:
Catalan Numbers on Rosetta Code
smart BASIC Rocks!
- Scott : San Diego, California
- Scott : San Diego, California
-
- Posts: 822
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Catalan Numbers on Rosetta Code
A loose guess: "with memorization" = "recursive" ?
- sarossell
- Posts: 195
- Joined: Sat Nov 05, 2016 6:31 pm
- My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
- Flag:
- Contact:
Re: Catalan Numbers on Rosetta Code
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
- Scott : San Diego, California
- Dutchman
- Posts: 860
- Joined: Mon May 06, 2013 9:21 am
- My devices: iMac, iPad Air, iPhone
- Location: Netherlands
- Flag:
Re: Catalan Numbers on Rosetta Code
I understand that with 'memoization' previous results are stored and looked-up if required again.
- sarossell
- Posts: 195
- Joined: Sat Nov 05, 2016 6:31 pm
- My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
- Flag:
- Contact:
Re: Catalan Numbers on Rosetta Code
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
- Scott : San Diego, California
- Dutchman
- Posts: 860
- Joined: Mon May 06, 2013 9:21 am
- My devices: iMac, iPad Air, iPhone
- Location: Netherlands
- Flag:
Re: Catalan Numbers on Rosetta Code
Yes but how do you know, in a fast way, which values have been stored?sarossell wrote: It would just store each value as it's generated. …

- sarossell
- Posts: 195
- Joined: Sat Nov 05, 2016 6:31 pm
- My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
- Flag:
- Contact:
Re: Catalan Numbers on Rosetta Code
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
- Scott : San Diego, California