Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created January 6, 2011 14:10
Show Gist options
  • Save juanplopes/767925 to your computer and use it in GitHub Desktop.
Save juanplopes/767925 to your computer and use it in GitHub Desktop.
def e(h,w,r,c)
return r+c-1 if (r==1 || c==w)
return e(h,w,h-r+1,w-c+1)+h+w-2 if (r==h || c==1);
return e(h-2,w-2,r-1,c-1)+2*(h+w-2);
end
a,b=gets.split.map(&:to_i)
d=Math.log10(a*b).to_i + 1
for i in 1..a
for j in 1..b
printf "%#{d}d ", e(a,b,i,j)
end
puts nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment