Skip to content

A faulty code passing all tests #217

Open
@ericguirbal

Description

@ericguirbal

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)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions