Skip to content

Instantly share code, notes, and snippets.

@ayato-p
Last active December 12, 2015 12:49
Show Gist options
  • Save ayato-p/4774796 to your computer and use it in GitHub Desktop.
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
(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