I'm so sorry, I did not receive a notification about this post, I'm just seeing it now for the first time.
The basic idea for j is to have a recursive function that caches its values.
The simplest syntax is: x a f j
where f is the function block, x is the parameter for which you want to calculate f(x), and a is a value or an array of values to start with, i.e. f(0), f(1), ... (it can also be an empty array). The "return values" are cached for all invocations, and when using j inside the block, it calls itself recursively, using the cache if available.
Memoized factorial: 5 1{_(j*}j
1 is 0!, and the block does n*(n-1)!
Memoized "n-th fibonacci number": 10 2,{(_j\(j+}j
In the latest release (0.6.3) I improved j to use a map so it can cache values sparsely (in older versions it used a contiguous array), it can work with multiple parameters (by adding the number of parameters right before j, as in x1 x2 ... xn a f n j) and also with any types, not just positive integers.
Here's the Levenshtein distance implemented directly on strings:
I have no idea what
jdoes. Could you please explain?I'm so sorry, I did not receive a notification about this post, I'm just seeing it now for the first time.
The basic idea for
jis to have a recursive function that caches its values.The simplest syntax is:
x a f jwhere
fis the function block,xis the parameter for which you want to calculate f(x), andais a value or an array of values to start with, i.e. f(0), f(1), ... (it can also be an empty array). The "return values" are cached for all invocations, and when usingjinside the block, it calls itself recursively, using the cache if available.Memoized factorial:
5 1{_(j*}j1 is 0!, and the block does n*(n-1)!
Memoized "n-th fibonacci number":
10 2,{(_j\(j+}jIn the latest release (0.6.3) I improved
jto use a map so it can cache values sparsely (in older versions it used a contiguous array), it can work with multiple parameters (by adding the number of parameters right beforej, as inx1 x2 ... xn a f n j) and also with any types, not just positive integers.Here's the Levenshtein distance implemented directly on strings:
"ginger""ninja" L{1$1$={;;0}{_{\_{[[[\]_:)2/z~:a]:~~=!2$2$j+\4$j)@3$j)]2>$0=}{;,}?}{;,}?}?}2j(haven't spent too much time on golfing it or making it nice)
I didn't receive a notification for your reply either.
I get it now. Thank you.
Bump. :P