Sha256: a2e3cb0c9162026cde0894dee17e4dc3226e64d3c351ec0445e41b2ff4ddabc1
Contents?: true
Size: 375 Bytes
Versions: 84
Compression:
Stored size: 375 Bytes
Contents
-module(binary_string). % binary is a "sticky module" so we have to use another name. -export( [to_decimal/1] ). to_decimal( String ) -> try {_N, Result} = lists:foldr( fun to_decimal/2, {0, 0}, String ), Result catch _:_ -> 0 end. 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
84 entries across 84 versions & 1 rubygems