fork download
  1. ; distinct characters
  2.  
  3. (define (distinct? str)
  4. (call-with-current-continuation
  5. (lambda (return)
  6. (let ((cs (string->list str)))
  7. (do ((cs cs (cdr cs))) ((null? cs) #t)
  8. (do ((ds (cdr cs) (cdr ds))) ((null? ds))
  9. (when (char=? (car cs) (car ds))
  10. (return #f))))))))
  11.  
  12. (display (distinct? "Programming")) (display " ")
  13. (display (distinct? "Praxis")) (newline)
  14.  
  15. (define (distinct? str)
  16. (let loop ((cs (sort (string->list str) char<?)))
  17. (if (null? (cdr cs)) #t
  18. (if (char=? (car cs) (cadr cs)) #f
  19. (loop (cdr cs))))))
  20.  
  21. (display (distinct? "Programming")) (display " ")
  22. (display (distinct? "Praxis")) (newline)
  23.  
  24. (define (distinct? str)
  25. (let ((letters (make-hash-table)))
  26. (let loop ((cs (string->list str)))
  27. (if (null? cs) #t
  28. (if (hash-ref letters (car cs) #f) #f
  29. (begin (hash-set! letters (car cs) 1)
  30. (loop (cdr cs))))))))
  31.  
  32. (display (distinct? "Programming")) (display " ")
  33. (display (distinct? "Praxis")) (newline)
Success #stdin #stdout 0.01s 42848KB
stdin
Standard input is empty
stdout
#f #t
#f #t
#f #t