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.0.8.36 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.35 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.34 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.33 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.32 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.31 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.30 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.29 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.28 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.27 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.26 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.24 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.23 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.22 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.21 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.20 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.19 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.18 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.17 tracks/erlang/exercises/allergies/src/example.erl
trackler-2.0.8.16 tracks/erlang/exercises/allergies/src/example.erl