Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Vous vous y prenez tard !
  2. Mieux vaut donc se limiter à un seul point.
  3.  
  4. A la fin de la séance de lundi dernier nous avons vu la fonction suivante:
  5.  
  6. ;; Si l est un ensemble (liste sans répétitions) de n objets
  7. ;; et si k est un entier naturel ne dépassant pas n
  8. ;; alors la fonction renvoie la liste de toutes
  9. ;; les partitions de l en k parties
  10. (define k-partitions
  11. (lambda (l n k)
  12. (if (= n 0)
  13. (if (= k 0) '(()) '())
  14. (let ((rec1 (k-partitions (cdr l) (- n 1) (- k 1)))
  15. (rec2 (k-partitions (cdr l) (- n 1) k)))
  16. (append (insert-in-all (list (car l)) rec1)
  17. (apply append
  18. (map (lambda (part)
  19. (insert-in-one (car l) part))
  20. rec2)))))))
  21. ;; (k-partitions '(a b c d) 4 2)
  22. ;; '(((a) (b c d))
  23. ;; ((a b) (c d))
  24. ;; ((b) (a c d))
  25. ;; ((a b c) (d))
  26. ;; ((b c) (a d))
  27. ;; ((a c) (b d))
  28. ;; ((c) (a b d)))
  29.  
  30. Cette fonction utilise deux fonctions auxiliaires:
  31. insert-in-all, dont nous avons vu la spécification et le code, et
  32. insert-in-one, dont vous devez écrire la spécification et le code.
  33.  
  34. Bien cordialement,
  35.  
  36. P. Gribomont
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement