2 points by akkartik 2369 days ago | link | parent Nice example. For exposition is it useful to simplify the problem by focusing on lists?`````` (def first-difference(seq1 seq2) (if (or no.seq1 no.seq2 (~iso car.seq1 car.seq2)) 0 (+ 1 (first-difference cdr.seq1 cdr.seq2)))) `````` Edit: no, that's not right, because it doesn't return nil on identical sequences. Here are two variants with and without the accumulator. Which is easier for noobs?`````` (def first-difference(seq1 seq2 (o pos 0)) (if (and no.seq1 no.seq2) nil (or no.seq1 no.seq2 (~iso car.seq1 car.seq2)) pos 'else (first-difference cdr.seq1 cdr.seq2 (+ pos 1)))) (def first-difference(seq1 seq2) (if (and no.seq1 no.seq2) nil (or no.seq1 no.seq2 (~iso car.seq1 car.seq2)) 0 'else (only.+ (first-difference cdr.seq1 cdr.seq2) 1))) (test-iso "" 0 (first-difference nil '(34))) (test-iso "" nil (first-difference '(1) '(1))) (test-iso "" 1 (first-difference '(1) '(1 2))) (test-iso "" 3 (first-difference '(1 2 3 4) '(1 2 3)))``````
 1 point by jsgrahamus 2368 days ago | link `````` arc> (def 1st-diff (str1 str2 i) (if (or (is str1 "") (is str2 "")) 0 (or (> i (- (len str1) 1)) (> i (- (len str2) 1))) i (no (is (str1 i) (str2 i))) i (1st-diff str1 str2 (+ i 1)))) # arc> (1st-diff "" "" 0) 0 arc> (1st-diff "" "" 0) 0 arc> (= astring "abcde") "abcde" arc> (= bstring "abced") "abced" arc> (1st-diff "" "" 0) 0 arc> (1st-diff astring "" 0) 0 arc> (1st-diff "" astring 0) 0 arc> (1st-diff astring bstring 0) 3 arc> (1st-diff bstring astring 0) 3 arc> (1st-diff astring "abcdef" 0) 5 arc> (1st-diff "abcdef" astring 0) 5 arc>``````-----
 2 points by jsgrahamus 2368 days ago | link Great.I'm used to seeing it as the empty stringHere is the expanded M version (! = LF):`````` IF X=Y WRITE !,0 ; No difference ELSE FOR I=1:1 IF \$EXTRACT(X,I)'=\$EXTRACT(Y,I) WRITE !,I QUIT``````-----