Sha256: 8237aa72da64c20646098c6048c53838a075b03addf03e161920b547bac3e371

Contents?: true

Size: 309 Bytes

Versions: 84

Compression:

Stored size: 309 Bytes

Contents

-module(grains).
-export([square/1, total/0]).

square(N) ->
  square(N, 1).

square(1, Acc) ->
  Acc;
square(N, Acc) ->
  square(N - 1, Acc * 2).

total() ->
  % Not the most efficient, but is passes.
  lists:foldl(fun(Elem, Acc) -> square(Elem) + Acc end,
              0,
              lists:seq(1, 64)).

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
trackler-2.0.5.7 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.6 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.5 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.4 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.3 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.2 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.1 tracks/erlang/exercises/grains/example.erl
trackler-2.0.5.0 tracks/erlang/exercises/grains/example.erl
trackler-2.0.4.0 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.9 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.8 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.7 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.6 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.5 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.4 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.3 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.2 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.1 tracks/erlang/exercises/grains/example.erl
trackler-2.0.3.0 tracks/erlang/exercises/grains/example.erl
trackler-2.0.2.0 tracks/erlang/exercises/grains/example.erl