(define (lev a b) (define (lev_ i j) (cond ((zero? (min i j)) (max i j)) (else (min (+ 1 (lev_ (- i 1) j)) (+ 1 (lev_ i (- j 1))) (+ (if (char=? (string-ref a i) (string-ref b j)) 0 1) (lev_ (- i 1) (- j 1))))))) (lev_ (- (string-length a) 1) (- (string-length b) 1))) (define (mostSimilar arr word) (define (mostSimilar_ arr acc_word acc_lev) (cond ((null? arr) acc_word) (else (let ((new_lev (lev (car arr) word))) (if (> acc_lev new_lev) (mostSimilar_ (cdr arr) (car arr) new_lev) (mostSimilar_ (cdr arr) acc_word acc_lev)))))) (mostSimilar_ (cdr arr) (car arr) (lev (car arr) word))) (format #t "Result: ~a~%" (mostSimilar (list "strawberry" "bean" "banana" "cherry") "berry"))
Sorry I typed on my phone.
Will optimise The levenstein function asap. Right now Tail call optimization doesn’t apply.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Sorry I typed on my phone.
Will optimise The levenstein function asap. Right now Tail call optimization doesn’t apply.