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