racket icon indicating copy to clipboard operation
racket copied to clipboard

A faulty code passing all tests

Open ericguirbal opened this issue 4 years ago • 0 comments

My first attempt (see below) to solve this exercise passed all tests but was faulty. It didn't raise an exception when the first argument of hamming-distance has a smaller length than the latter. So I suggest to add a test.

#lang racket
 
(define (distance eq lst1 lst2 [acc 0])
  (cond
    [(empty? lst1) acc]
    [(eq (first lst1) (first lst2)) (distance eq (rest lst1) (rest lst2) acc)]
    [(distance eq (rest lst1) (rest lst2) (add1 acc))]))

(define (hamming-distance strand1 strand2)
  (distance char=? (string->list strand1) (string->list strand2)))

ericguirbal avatar Feb 01 '22 02:02 ericguirbal