-nl sub J{map$_[$s-$_].=pop,1..$s;@_}$s=8;sub S{/./g;$&^t||!($s/=2)?($&x$s)x$s:(J(&S,&S),J&S,&S)x!!($s*=2)}print for S