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.139 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.138 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.137 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.136 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.135 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.134 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.133 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.132 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.131 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.130 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.129 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.128 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.127 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.126 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.125 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.124 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.123 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.122 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.121 tracks/erlang/exercises/spiral-matrix/src/example.erl
trackler-2.2.1.120 tracks/erlang/exercises/spiral-matrix/src/example.erl