How do I implement a program in Scheme taking the elements of a given list and returning a new list where the elements are random gatherings of the previous list? I would like it to work for any length. For example:
Input: '(a e i o u)
, output: '((a e) (i o) (u))
for length 2.
My attempts (making use of for/list) are being clumsy and based on recursion. I have divided the tasks as suggested by Óscar:
Select n elements randomly from a list l:
(define (pick-n-random l n) (take (shuffle l) n))
Remove a list l2 from a list l1:
(define (cut l1 l2) (cond ((null? l1) '()) ((not (member (car l1) l2)) (cons (car l1) (cut (cdr l1) l2))) (else (cut (cdr l1) l2))))
Then, and that is my problem: how do I recurse over this process to get the intended program? Should I use for/list
to paste all sublists got by this process 1. and 2.?