Created
April 3, 2022 17:12
-
-
Save samdphillips/844cdc3356681ba2ba0fd5aefc77e214 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
(define (apples a-string) | |
(define string-size (string-length a-string)) | |
(define (once current count i) | |
(cond | |
[(= i string-size) | |
(if current | |
(list (cons current count)) | |
null)] | |
[else | |
(define ch (string-ref a-string i)) | |
(cond | |
[(not current) (once ch 1 (add1 i))] | |
[(char=? ch current) (once current (add1 count) (add1 i))] | |
[else | |
(cons (cons current count) | |
(once ch 1 (add1 i)))])])) | |
(once #f #f 0)) | |
(apples "aaaabbbcca") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment