1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
DistributeElements=.{{ F=.{{ NB. couldn't get structural under to work :( a=.>y i=.<:/{:@>a <a i}~<(>x),~>i{a }} ,&>/>F/(<"0|.2}.y),<<"0]2{.y }} echo DistributeElements 2 1 3 4 5 echo DistributeElements 3 2 4 echo DistributeElements 5 4 3 8 exit ''