diff --git a/exercises/practice/binary/.meta/example.lfe b/exercises/practice/binary/.meta/example.lfe index 29118572..7134f8b1 100644 --- a/exercises/practice/binary/.meta/example.lfe +++ b/exercises/practice/binary/.meta/example.lfe @@ -2,9 +2,5 @@ (export (to-decimal 1))) (defun to-decimal (string) - (try (element 2 (lists:foldr #'to-decimal/2 #(0 0) string)) - (catch (_ 0)))) + (list_to_integer string 2)) -(defun to-decimal - ([#\0 `#(,n ,acc)] `#(,(+ n 1) ,acc)) - ([#\1 `#(,n ,acc)] `#(,(+ n 1) ,(+ acc (trunc (math:pow 2 n)))))) diff --git a/exercises/practice/binary/src/binary.app.src b/exercises/practice/binary/src/binary-string.app.src similarity index 76% rename from exercises/practice/binary/src/binary.app.src rename to exercises/practice/binary/src/binary-string.app.src index 29189268..248f2390 100644 --- a/exercises/practice/binary/src/binary.app.src +++ b/exercises/practice/binary/src/binary-string.app.src @@ -1,9 +1,9 @@ %% -*- erlang -*- -{application, 'binary', +{application, 'binary-string', [{description, ""}, {vsn, "0.0.1"}, {modules, - ['binary']}, + ['binary-string']}, {registered, []}, {applications, [kernel, stdlib]}, diff --git a/exercises/practice/binary/src/binary-string.lfe b/exercises/practice/binary/src/binary-string.lfe index e69de29b..a9a54a97 100644 --- a/exercises/practice/binary/src/binary-string.lfe +++ b/exercises/practice/binary/src/binary-string.lfe @@ -0,0 +1,5 @@ +(defmodule binary-string + (export (to-decimal 1))) + +; please implement the to-decimal function + diff --git a/exercises/practice/binary/test/binary-string-tests.lfe b/exercises/practice/binary/test/binary-string-tests.lfe index f756b6f6..4cca440b 100644 --- a/exercises/practice/binary/test/binary-string-tests.lfe +++ b/exercises/practice/binary/test/binary-string-tests.lfe @@ -4,21 +4,27 @@ (include-lib "ltest/include/ltest-macros.lfe") -(deftest one (check "1")) +(deftest binary-0-is-decimal-0 + (is-equal 0 (binary-string:to-decimal "0"))) -(deftest two (check "10")) +(deftest binary-1-is-decimal-1 + (is-equal 1 (binary-string:to-decimal "1"))) -(deftest three (check "11")) +(deftest binary-10-is-decimal-2 + (is-equal 2 (binary-string:to-decimal "10"))) -(deftest four (check "100")) +(deftest binary-11-is-decimal-3 + (is-equal 3 (binary-string:to-decimal "11"))) -(deftest nine (check "1001")) +(deftest binary-100-is-decimal-4 + (is-equal 4 (binary-string:to-decimal "100"))) -(deftest twenty-six (check "11010")) +(deftest binary-1001-is-decimal-9 + (is-equal 9 (binary-string:to-decimal "1001"))) -(deftest large (check "10001101000")) +(deftest binary-11010-is-decimal-26 + (is-equal 26 (binary-string:to-decimal "11010"))) -(deftest carrot (is-equal 0 (binary-string:to-decimal "carrot"))) +(deftest binary-10001101000-is-decimal-1128 + (is-equal 1128 (binary-string:to-decimal "10001101000"))) -(defun check (string) - (is-equal (list_to_integer string 2) (binary-string:to-decimal string)))