-
-
Save SaitoAtsushi/492201 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
(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) |
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 gauche.collection) | |
(define (pick-toothless ls) | |
(reverse! | |
(fold2 | |
(^(e r i)(until(= i e)(push! r i)(inc! i))(values r(+ i 1))) | |
'() | |
(car ls) | |
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