Skip to content

Commit

Permalink
Simplify example
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Jun 24, 2024
1 parent 8f919c9 commit 062d994
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions exercises/practice/binary/.meta/example.lfe
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
(defmodule binary
(export (to-decimal 1)))

(defun to-decimal (string)
(try (element 2 (lists:foldr #'to-decimal/2 #(0 0) string))
(catch (_ 0))))
(defun to-decimal (number)
(list_to_integer number 2))

(defun to-decimal
([#\0 `#(,n ,acc)] `#(,(+ n 1) ,acc))
([#\1 `#(,n ,acc)] `#(,(+ n 1) ,(+ acc (trunc (math:pow 2 n))))))

0 comments on commit 062d994

Please sign in to comment.