简体   繁体   English

方案二进制列表到十进制和

[英]Scheme Binary List to Decimal Sum

A function that takes a list of binary numbers and returns their decimal sum.一个接受二进制数列表并返回它们的十进制和的函数。

Call: (addBinary '(1101 111 10 101))

(define (addBinary binaryList))

returns 27

Tested in Guile and Racket:在 Guile 和 Racket 中测试:

(define (addBinary binaryList)
  (apply +
         (map (lambda (n)
                (string->number
                 (number->string n) 2))
              binaryList)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM