Created
July 24, 2010 06:52
-
-
Save valvallow/488483 to your computer and use it in GitHub Desktop.
pick-toothless, scheme, gauche
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
(define (pick-toothless ls) | |
(let rec ((ls ls)(acc '())) | |
(if (or (null? ls) | |
(null? (cdr ls))) | |
(reverse acc) | |
(let1 next (+ (car ls) 1) | |
(if (= next (cadr ls)) | |
(rec (cdr ls) acc) | |
(rec (cons next (cdr ls)) | |
(cons next acc))))))) | |
(pick-toothless '(1 2 3 5 6 8 9)) | |
;; (4 7) | |
(pick-toothless '(1 2 4 5 10)) | |
;; (3 6 7 8 9) | |
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
(use srfi-1) | |
(define (pick-toothless ls) | |
(if (null? ls) | |
'() | |
(let ((min (car ls))(max (last ls))) | |
(let1 pls (iota (+ (- max min) 1) min) | |
(lset-difference = pls ls))))) | |
(pick-toothless '(1 2 3 5 6 8 9)) | |
;; (4 7) | |
(pick-toothless '(1 2 4 5 10)) | |
;; (3 6 7 8 9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment