Matlab, 123
function r=m(h)\np=[h rot90(h) rot90(h,2) rot90(h,3)]\nfor i=2:size(p)\np(i,:)=max(p(i,:),p(i-1,:))\nend\nr=sum(diff(p)>0)+1\nend
used like this:
m([
4 3 5 2 1;
5 4 1 3 2;
1 5 2 4 3;
2 1 3 5 4;
3 2 4 1 5])
[2 3 1 4 5 3 4 3 2 1 1 2 2 2 2 3 3 2 1 2]
C#, down to 354...
Different approach than TheBestOne used.
using System;
using System.Linq;
class A
{
static void Main(string[] h)
{
int m = (int)Math.Sqrt(h[0].Length),k=0;
var x = h[0].Select(c => c - 48);
var s = Enumerable.Range(0, m);
for (; k < 4; k++)
{
(k%2 == 0 ? s : s.Reverse())
.Select(j =>
(k > 0 && k < 3 ? x.Reverse() : x).Where((c, i) => (k % 2 == 0 ? i % m : i / m) == j)
.Aggregate(0, (p, c) =>
c > p%10
? c + 10 + p/10*10
: p, c => c/10))
.ToList()
.ForEach(Console.Write);
}
}
}