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

Add Hamming exercise. #49

Merged
merged 1 commit into from
Jun 3, 2017
Merged

Add Hamming exercise. #49

merged 1 commit into from
Jun 3, 2017

Conversation

stevejb71
Copy link
Contributor

No description provided.

@paf31 paf31 merged commit 98c011a into exercism:master Jun 3, 2017
@paf31
Copy link
Contributor

paf31 commented Jun 3, 2017

Looks great, thanks!

I think there is a one liner version too:

hamming xs ys = guard (length xs == length ys) $> length (filter id (zipWith (/=) xs ys))

😄

distance dna1 dna2 = case Tuple (uncons dna1) (uncons dna2) of
Tuple (Just {head: h1, tail: t1}) (Just {head: h2, tail: t2}) -> (if h1 /= h2 then ((+) 1) else id) <$> distance t1 t2
Tuple Nothing Nothing -> Just 0
Tuple _ _ -> Nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of file newline is missing here.

Could this have been written with multiple function clauses?

@@ -0,0 +1,46 @@
-- Test/exercise version: "1.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

@stevejb71
Copy link
Contributor Author

stevejb71 commented Jun 4, 2017

I put a comment with the version number from the canonical data in. It should help keep track if new common tests are added, or the spec for the exercise is changed.

Why is the new line at end of file important?

A solution using zipWith similar to @paf31's would be neater. Do you want me to update it?

@stevejb71 stevejb71 deleted the AddHamming branch June 4, 2017 10:20
@lpil
Copy link
Member

lpil commented Jun 4, 2017

I think the solution is good :)

It's the version comment an​ established convention in exercism?

@stevejb71
Copy link
Contributor Author

Some streams look to be doing this:
exercism/discussions#133

I maintain the ocaml stream and have added versions to a majority of tests.

@lpil
Copy link
Member

lpil commented Jun 4, 2017

Seems like a good addition then. Thank you :)

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

Successfully merging this pull request may close these issues.

3 participants