#lang typed/racket/base(require math/array)
(: shortest-edit-distance (-> String String Integer))(define (shortest-edit-distance str0 str1) (let* ([l0 : Integer (string-length str0)] [l1 : Integer (string-length str1)] [table : (Mutable-Array Integer) (array->mutable-array (make-array (vector l0 l1) 0))]) (for*/last : Integer ([i0 : Integer (in-range l0)] [i1 : Integer (in-range l1)]) (let* ([c0 : Char (string-ref str0 i0)] [c1 : Char (string-ref str1 i1)] [base : Integer (cond [(and (= i0 0) (= i1 0)) 0] [(= i0 0) (array-ref table (vector i0 (sub1 i1)))] [(= i1 0) (array-ref table (vector (sub1 i0) i1))] [else (min (array-ref table (vector i0 (sub1 i1))) (array-ref table (vector (sub1 i0) i1)) (array-ref table (vector (sub1 i0) (sub1 i1))))])] [answer : Integer (if (char=? c0 c1) base (add1 base))]) (array-set! table (vector i0 i1) answer) answer))))

<截屏2019-07-0800.15.13.png>
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/1fa2f544-9f60-4e00-a451-b42b1e4f5b0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<截屏2019-07-0800.15.13.png>
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.
On Jul 7, 2019, at 10:24 AM, 曹朝 <cz1...@gmail.com> wrote: