Skip to content

Instantly share code, notes, and snippets.

@vu3rdd
Created June 17, 2012 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vu3rdd/2944997 to your computer and use it in GitHub Desktop.
Save vu3rdd/2944997 to your computer and use it in GitHub Desktop.
distinct?
#lang racket
(require rackunit)
(define (distinct? xs)
(= (set-count (list->set xs)) (length xs)))
(check-equal? (distinct? '()) #t)
(check-equal? (distinct? '(1)) #t)
(check-equal? (distinct? '(1 2)) #t)
(check-equal? (distinct? '(1 1)) #f)
(check-equal? (distinct? '(1 2 3)) #t)
(check-equal? (distinct? '(1 2 3 3 2)) #f)
(check-equal? (distinct? '(a b)) #t)
(check-equal? (distinct? '(a b a)) #f)
(check-equal? (distinct? '(a b c c)) #f)
(check-equal? (distinct? '(1 2 3 4)) #t)
(check-equal? (distinct? '(1 2 3 4 5)) #t)
(check-equal? (distinct? '(1 (2 3) 4 2 3)) #t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment