Sha256: e7a6e7bceec3e277a20afb3e7badc5ea7665e821894681cc8d1dd02997b5dbfd

Contents?: true

Size: 411 Bytes

Versions: 15

Compression:

Stored size: 411 Bytes

Contents

-module(example). % binary is a "sticky module" so we have to use another name.
-export( [to_decimal/1, test_version/0] ).

to_decimal( String ) ->
  try
    {_N, Result} = lists:foldr( fun to_decimal/2, {0, 0}, String ),
    Result

  catch
    _:_ -> 0

  end.

test_version() ->
    1.



to_decimal( $0, {N, Acc} ) -> {N + 1, Acc};
to_decimal( $1, {N, Acc} ) -> {N + 1, Acc + erlang:trunc(math:pow(2, N))}.

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
trackler-2.0.7.0 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.44 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.43 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.42 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.41 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.40 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.39 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.38 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.37 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.36 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.35 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.34 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.33 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.32 tracks/erlang/exercises/binary/src/example.erl
trackler-2.0.6.31 tracks/erlang/exercises/binary/src/example.erl