There's some more magic in k4, I'm trying to figure out but I'm still a little confused about the above. Here's what I get from a fresh K session.
kona \ for help. \\ to exit.
vs:{vs:{(*y%x;(*|y),*y!x)};{*|{~0=*x}{vs[y]x}[;y]/x}[;x](y;())}
vs[9;15]
type error
> vs:{vs1:{(*y%x;(*|y),*y!x)};{*|{~0=*x}{vs1[y]x}[;y]/x}[;x](y;())}
> \
vs[9;15]
rank errorI'm not sure why I would get different errors just by changing the name. It looks like you can make local functions:
kona \ for help. \\ to exit.
fn:{f1:{x*2};f1[x]}
fn 3
6
f1
value error
f1
^
This was unexpected though. It looks like f1 is somehow simply ignored. I would have expected a value error.
fn:{f2:{x*2};f1[x]}
fn 3
3
f2
value error
f2
In the end I changed vs to the following: vs:{{*|{~0=*x}{(*x%y;(*x!y),*|x)}[;y]/x}[;x](y;())} which doesn't use a local function. It also fixes a bug where the digits are in the reverse order which is mostly why I'm reposting now. I think I got the first line of the solver translated now. There seems to be some magic in k4 which lines up vectors somehow which I had to do by hand below. For instance p1 has shape 81 2 and p has shape 8, but joining them creates an object of shape 81 3. Also, when generating base 9 digits with vs, some are two digit and others are one digit, but the shape is still somehow 81 2 instead of a list of mixed lengths.
The second line seems to mostly work, but there is some magic in @[x;y;:] somehow filling in possible values. I'm not clear where those possible values are coming from.
sv:{:[0=#y;0;{z+x*y}[x]/y]}
vs:{{*|{~0=*x}{(*x%y;(*x!y),*|x)}[;y]/x}[;x](y;())}
p:sv[3]'(p1:{(&2-#x),x}'vs[9]'!81)%3
p:+{(*x),*|x}'+(p;p1)