[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/kWBmScj6    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Aug 16:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
; first non-repeating character

(define (first-non-rep-char str)
  (let ((freq (make-vector 256 0)))
    (do ((j 0 (+ j 1))) ((= j (string-length str)))
      (let* ((c (string-ref str j)) (i (char->integer c)))
        (vector-set! freq i (+ (vector-ref freq i) 1))))
    (let loop ((j 0))
      (let* ((c (string-ref str j)) (i (char->integer c)))
        (cond ((= j (string-length str)) #f)
              ((= (vector-ref freq i) 1) c)
              (else (loop (+ j 1))))))))

(display (first-non-rep-char "aabcbcdeef"))


Output:
1
d


Create a new paste based on this one


Comments: