Last active
October 16, 2016 04:37
-
-
Save 97jaz/add792e0bc4a24d18f8438bc97cb3f1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
;; others: generates a list of characters in `str` *other* | |
;; than the one at index `pos` | |
(define (others str pos [i 0] [res '()]) | |
(cond [(= i (string-length str)) | |
(reverse res)] | |
[(= pos i) | |
(others str pos (add1 i) res)] | |
[else | |
(others str pos (add1 i) (cons (string-ref str i) res))])) | |
;; each+others: generates a list of lists of characters. Each | |
;; list's first element is a unique character of `str` and the | |
;; rest of the elements are the rest of the string's characters. | |
(define (each+others str [i 0] [res '()]) | |
(cond [(= i (string-length str)) | |
(reverse res)] | |
[else (each+others str | |
(add1 i) | |
(cons (cons (string-ref str i) (others str i)) | |
res))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment