Calculating catalan numbers with memoization


This question is an exact duplicate of:


You need to pass the cache to your recursive calls:

sum = sum + catalan_mem(i, mem) * catalan_mem(n-i-1, mem)

Otherwise, every method call creates a new empty cache.

Need Your Help

Get format string from formatted date using PHP

php date

Is it possible to get the format of a formatted date string in PHP?