Sha256: b0594c95d18057043ebf5e5631ee77887aa1c56ece676016ae48872483b1a8d2

Contents?: true

Size: 838 Bytes

Versions: 84

Compression:

Stored size: 838 Bytes

Contents

-module(allergies).

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

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

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.

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
trackler-2.0.6.28 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.27 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.26 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.25 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.24 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.23 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.22 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.21 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.20 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.19 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.18 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.17 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.16 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.15 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.14 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.13 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.12 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.11 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.10 tracks/erlang/exercises/allergies/example.erl
trackler-2.0.6.9 tracks/erlang/exercises/allergies/example.erl