blob: 2a2fba386c3da034ea827881a9ef9b7a9d9cdca3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
;;; binary.el --- Binary exercise (exercism)
;;; Commentary:
;;; Code:
(require 'cl)
(defun to-decimal-helper (str)
(cl-loop with result = 0
for c across str
do (setq result (+ (- c ?0) (* 2 result)))
finally return result))
(defun to-decimal (str)
(if (string-match "[01]+" str)
(to-decimal-helper str)
0))
(provide 'binary)
;;; binary.el ends here
|