Sha256: 81aa63b9a3e09103accbca099bbfe4473c2dd71aa30cbac931f52e883b892765

Contents?: true

Size: 904 Bytes

Versions: 310

Compression:

Stored size: 904 Bytes

Contents

-module(example).

-export([allergies/1, is_allergic_to/2, test_version/0]).

-define(ALLERGIES, ['eggs',         % 2^0
                    'peanuts',      % 2^1
                    'shellfish',    % 2^2
                    'strawberries', % 2^3
                    'tomatoes',     % 2^4
                    'chocolate',    % 2^5
                    'pollen',       % 2^6
                    'cats']).       % 2^7

allergies(Score) ->
  lists:filter(fun (X) -> is_allergic_to(X, Score) end, ?ALLERGIES).

is_allergic_to(Allergy, Score) ->
  Index = indexOf(Allergy, ?ALLERGIES),
  case Index of
    not_found ->
      false;
    _ ->
      (Score band trunc(math:pow(2, Index))) > 0.0
  end.

indexOf(A, Allergies) ->
  index(0, Allergies, A).

index(Index, [A|_], A) ->
  Index;
index(Index, [_|Allergies], A) ->
  index(Index+1, Allergies, A);
index(_, [], _) ->
  not_found.

test_version() ->
    1.

Version data entries

310 entries across 310 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.179 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.178 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.177 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.176 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.175 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.174 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.173 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.172 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.171 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.170 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.169 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.167 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.166 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.165 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.164 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.163 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.162 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.161 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.2.1.160 tracks/erlang/exercises/allergies/src/example.erl