Created
January 23, 2010 18:06
-
-
Save kidd/284708 to your computer and use it in GitHub Desktop.
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
| ;;; permutations with repetitions. Base to get all possible | |
| ;;; mastermind solutions. | |
| ;;; | |
| ;;; Example usage: | |
| ;;; (perm '(1 2 3) 2) => ((1 1) (2 1) (3 1) (1 2) (2 2) (3 2) (1 3) (2 3) (3 3)) | |
| (define (perm lst len) | |
| (cond ((= 0 len) '(())) | |
| (else (append-map (lambda (x) | |
| (map (lambda (y) (cons y x )) lst)) | |
| (perm lst (- len 1)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment