Skip to main content
edited body
Source Link
function r=m(h) p=[h;p=[h rot90(h) rot90(h,2) rot90(h,3)] for];for i=2:size(p) p(i,:)=max(p(i,:),p(i-1,:)) end r=sum;end;r=sum(diff(p)>0)+1
function r=m(h) p=[h rot90(h) rot90(h,2) rot90(h,3)] for i=2:size(p) p(i,:)=max(p(i,:),p(i-1,:)) end r=sum(diff(p)>0)+1
function r=m(h);p=[h rot90(h) rot90(h,2) rot90(h,3)];for i=2:size(p) p(i,:)=max(p(i,:),p(i-1,:));end;r=sum(diff(p)>0)+1
added 14 characters in body
Source Link
flawr
  • 43.9k
  • 7
  • 104
  • 249

Matlab, 123(123)(119)

function r=m(h)\np=[h p=[h rot90(h) rot90(h,2) rot90(h,3)]\nfor] for i=2:size(p)\np p(i,:)=max(p(i,:),p(i-1,:))\nend\nr=sum end r=sum(diff(p)>0)+1\nend+1

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

Matlab, (123)(119)

function r=m(h) p=[h rot90(h) rot90(h,2) rot90(h,3)] for i=2:size(p) p(i,:)=max(p(i,:),p(i-1,:)) end r=sum(diff(p)>0)+1
Source Link

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);
        }
    }
}