Skip to content

Instantly share code, notes, and snippets.

@SaitoAtsushi
Forked from valvallow/pick-toothless1.scm
Created July 27, 2010 13:15
Show Gist options
  • Save SaitoAtsushi/492201 to your computer and use it in GitHub Desktop.
Save SaitoAtsushi/492201 to your computer and use it in GitHub Desktop.
(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)
(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)
(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