update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
13
Task/Permutations/Racket/permutations.rkt
Normal file
13
Task/Permutations/Racket/permutations.rkt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#lang racket
|
||||
|
||||
;; using a builtin
|
||||
(permutations '(A B C))
|
||||
;; -> '((A B C) (B A C) (A C B) (C A B) (B C A) (C B A))
|
||||
|
||||
;; a random simple version (which is actually pretty good for a simple version)
|
||||
(define (perms l)
|
||||
(let loop ([l l] [tail '()])
|
||||
(if (null? l) (list tail)
|
||||
(append-map (λ(x) (loop (remq x l) (cons x tail))) l))))
|
||||
(perms '(A B C))
|
||||
;; -> '((C B A) (B C A) (C A B) (A C B) (B A C) (A B C))
|
||||
Loading…
Add table
Add a link
Reference in a new issue