Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A faulty code passing all tests #217

Open
ericguirbal opened this issue Feb 1, 2022 · 0 comments
Open

A faulty code passing all tests #217

ericguirbal opened this issue Feb 1, 2022 · 0 comments

Comments

@ericguirbal
Copy link

ericguirbal commented Feb 1, 2022

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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant