Advertisement
Jobjob

Programmation déclarative - Q1AB - 06/2012

Jan 5th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.60 KB | None | 0 0
  1. (define (number->list n)
  2.   (letrec
  3.       ((convert (lambda (x l)
  4.                  (if (= x 0)
  5.                      l
  6.                      (convert (truncate (/ x 10)) (cons (inexact->exact (modulo x 10)) l))
  7.                      )
  8.                   )
  9.                ))
  10.     (convert (exact->inexact n) '())
  11.     )
  12.   )
  13.  
  14. (define (fold f null l)
  15.   (if (eq? l '())
  16.       null
  17.       (fold f (f (car l) null) (cdr l))))
  18.  
  19. (define (multiple-de-3 n)
  20.   (if (or (= n 3) (= n 6) (= n 9))
  21.       #t
  22.       (if (< n 9)
  23.           #f
  24.           (multiple-de-3 (fold + 0 (number->list n)))
  25.           )
  26.       )
  27.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement