Skip to content

Instantly share code, notes, and snippets.

@97jaz
Created October 16, 2016 05:42
Show Gist options
  • Save 97jaz/7676e91efee02584f850f24e51b87d63 to your computer and use it in GitHub Desktop.
Save 97jaz/7676e91efee02584f850f24e51b87d63 to your computer and use it in GitHub Desktop.
#lang racket/base
(require racket/match)
(define (each+others/non-index cs [prev '()] [res '()])
(match cs
['() res]
[(cons c cs) (each+others/non-index cs
(cons c prev)
(cons (cons c (append prev cs)) res))]))
;; example:
;; > (each+others/non-index (string->list "hello"))
;; '((#\o #\l #\l #\e #\h) (#\l #\l #\e #\h #\o) (#\l #\e #\h #\l #\o) (#\e #\h #\l #\l #\o) (#\h #\e #\l #\l #\o))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment