fork(1) download
  1. f=->x,y{d=->a{-~a.map(&d).max||0 rescue 0}
  2. d[x]<d[y]?y.map{|e|f[x,e]}:d[x]>d[y]?x.map{|e|f[e,y]}:d[x]<1?x+(y||0):[*x.zip(y).map{|a,b|f[a,b]},*y[x.size..-1]]}
  3.  
  4. p f[[1, [2, [3, [4]]]] , [10, [20]]]
  5. p f[[-1, 0, 1] , [1]]
Success #stdin #stdout 0.05s 9664KB
stdin
Standard input is empty
stdout
[[11, [21]], [[12, [22]], [13, [24]]]]
[0, 0, 1]