fork(1) download
  1. (use-modules
  2. (srfi srfi-1)
  3. (ice-9 format)
  4. )
  5.  
  6. (define (recombine right left)
  7. (format #t "~a\n" (string-join (map number->string left) " ")) ; trace
  8.  
  9. (if (null? right)
  10. #f ; if right is empty then go out
  11.  
  12. (let ((tail (cdr right)) (next (cons (car right) left))) ; right & left for next step
  13. (recombine tail next) ; try to go deep
  14. (recombine tail left) ; next iteration
  15. )
  16. )
  17. )
  18.  
  19. (recombine (list 1 2 3 4) (list))
Success #stdin #stdout 0.03s 9768KB
stdin
Standard input is empty
stdout
1
2 1
3 2 1
4 3 2 1
3 2 1
2 1
4 2 1
2 1
1
3 1
4 3 1
3 1
1
4 1
1

2
3 2
4 3 2
3 2
2
4 2
2

3
4 3
3

4