Skip to content

Instantly share code, notes, and snippets.

@kidd
Created January 23, 2010 18:06
Show Gist options
  • Select an option

  • Save kidd/284708 to your computer and use it in GitHub Desktop.

Select an option

Save kidd/284708 to your computer and use it in GitHub Desktop.
;;; 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