Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ff m, *a
- return ->x{x+1} if m==0
- return ->f{->x{x.times{x=f[x]};x}} if m==1
- ->x{
- if a.size==m
- y=a[0], z=a[1]
- x.times{z=y[z]}
- a[2..-1].inject(z){|y,z|y[z]}[x]
- else
- ff m, [*a, x]
- end
- }
- end
- (ff 3)[ff 2][ff 1][ff 0][2]
- = ff(3, ff(2), ff(1), ff(0))[2]
- = (ff 2)[ff(2)[ff 1]][ff 0][2]
- = ff(2, ff(2)[ff 1], ff(0))[2]
- = ff(2)[ff 1][ff(2, ff(1), ff(0))][2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement