Sha256: 290856bcf822e9f41613620e1289e94553ca69696b941aa46275573bfb7a310e

Contents?: true

Size: 805 Bytes

Versions: 188

Compression:

Stored size: 805 Bytes

Contents

-module(example).
-export([test_version/0,make/1]).

test_version() -> 1.

make(N) ->
    Self = self(),
    Rows = Cols = lists:seq(1,N),
    lists:foreach(
      fun(Y) ->
              spawn_link(fun() ->
                                 Self ! {Y, [n(X,Y,N)||X<-Cols]}
                         end)
      end, Rows),
    lists:map(fun(Y) ->
                      receive
                          {Y, L} -> L
                      end
              end, Rows).

n(0,1,_)                        -> 0;
n(X,Y,N) when Y=:=X+1, X+Y=<N+1 -> n(X-1, Y-1, N) + 4*(N - 2*X + 1);
n(X,Y,N) when X+Y=<N+1, X-Y>=0  -> n(Y-1, Y, N) + X-Y+1;
n(X,Y,N) when X+Y>N+1, X-Y>=0   -> n(X, N+1-X, N) + X+Y-N-1;
n(X,Y,N) when X+Y>=N+1          -> n(Y, Y, N) + Y-X;
n(X,Y,N)                        -> n(X, N-X+1, N) + N+1-X-Y.

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.118 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.117 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.116 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.115 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.114 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.113 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.111 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.110 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.109 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.108 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.107 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.106 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.105 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.104 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.103 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.102 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.101 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.100 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.99 tracks/erlang/exercises/spiral-matrix/src/example.erl