f = ->w,h{s="%d%d"%[w,h]*q=w+h;a=[s[0,w]];(h-2).times{|i|a<<(s[2*q-5-i].ljust(w-1)+s[w+i,1])[-w,w]};puts a,h>1?(s[q-2,w].reverse):p} f.call(4,4) f.call(10,3) f.call(1,1) f.call(23,1) f.call(1,17)
Standard input is empty
4444 4 4 4 4 4444 1031031031 1 0 3013013013 1 23123123123123123123123 1 1 7 1 1 7 1 1 7 1 1 7 1 1 7 1 1