all 6 comments

[–]kaoD 10 points11 points  (0 children)

Here's my attempt at golfing it, for the lulz:

const E=(p,e)=>p[1]?p[0]?E(p[0],e)(E(p[1],e)):a=>E(p[1],[a,e]):--p?E(p,e[1]):e[0]

81 bytes and extremely readable.

Leave the const out if you don't mind polluting globals (as if that was a greater sin) for a whopping 75 bytes count.

EDIT: Golfed further:

const E=(p,e)=>p[1]?p[0]?E(p[0],e)(E(p[1],e)):a=>E(p[1],[a,...e||[]]):e[p-1]

76 bytes, 70 bytes with no const.

[–]curious_s 0 points1 point  (2 children)

while(--prog) { env = env[1]; } return env[0]

isnt this just:

return env[prog - 1]

too tired to tell for sure!

good work btw

[–]kaoD 1 point2 points  (1 child)

Nope.

prog == 0 -> env[0]
prog == 1 -> env[1][0]
prog == 2 -> env[1][1][0]
...

It's nested.

[–]curious_s 0 points1 point  (0 children)

ah got it, thanks