Last active
December 12, 2015 12:49
-
-
Save ayato-p/4774796 to your computer and use it in GitHub Desktop.
数のリストを合成する。
ex.) (1 2 3 4) ;;=> 1234
(1 0 0 0) ;;=> 1000
(0 0 0 1) ;;=> 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (comp-tup tup) | |
(comp-tup-iter tup 0)) | |
(define (comp-tup-iter tup comp) | |
(define (pow a b) | |
(if (zero? b) | |
1 | |
(* a (pow a (- b 1))))) | |
(cond | |
((null? tup) comp) | |
(else | |
(let ((size (- (length tup) 1))) | |
(let ((exp (pow 10 size)) | |
(x (car tup))) | |
(comp-tup-iter (cdr tup) (+ comp (* x exp)))))))) | |
(comp-tup '(1 2 3 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment