如何在方案中编写程序来查找数字列表的因子
How can write a program in scheme to find factors of a list of numbers
这是单个整数的代码,如何扩展到函数列表?
(define (factors n)
(define (*factors d)
(cond ((> d n) (list))
((= (modulo n d) 0) (cons d (*factors (+ d 1))))
(else (*factors (+ d 1)))))
(*factors 1))
(display (factors 1111111))
(newline)
您可以使用 for-each
遍历列表。
(define (factors n)
(define (*factors d)
(cond ((> d n) (list))
((= (modulo n d) 0) (cons d (*factors (+ d 1))))
(else (*factors (+ d 1)))))
(*factors 1))
(define arbitarily-large-input (list 10 11 12))
(for-each (lambda (x)
(display x)
(newline))
(map factors arbitarily-large-input))
这是单个整数的代码,如何扩展到函数列表?
(define (factors n)
(define (*factors d)
(cond ((> d n) (list))
((= (modulo n d) 0) (cons d (*factors (+ d 1))))
(else (*factors (+ d 1)))))
(*factors 1))
(display (factors 1111111))
(newline)
您可以使用 for-each
遍历列表。
(define (factors n)
(define (*factors d)
(cond ((> d n) (list))
((= (modulo n d) 0) (cons d (*factors (+ d 1))))
(else (*factors (+ d 1)))))
(*factors 1))
(define arbitarily-large-input (list 10 11 12))
(for-each (lambda (x)
(display x)
(newline))
(map factors arbitarily-large-input))