Skip to content

Instantly share code, notes, and snippets.

@valvallow
Created July 24, 2010 06:52
Show Gist options
  • Save valvallow/488483 to your computer and use it in GitHub Desktop.
Save valvallow/488483 to your computer and use it in GitHub Desktop.
pick-toothless, scheme, gauche
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment