<commit_before>---
layout: post
title: Hamming exercise
---

WWhen you try to become web developer there are obvious things you need to learn. HTML is the foundation of each website, so you learn that. Then you start to think that it would be nice if the website looked just a bit better and you learn CSS. Then you figure out you need some JS to make it more dynamic and some backend framework and in my case you start to learn Ruby on Rails. But, there is also one more important part, which shouldn't be neglected if you aspire to become good programmer someday. We should learn how to write clean code and in the case of using objective oriented language how to write good OOP code.

[Arkency](http://blog.arkency.com) knows that and they also live by DDD. When I talked to [<NAME>](https://twitter.com/andrzejkrzywda) he explained that learning how to write nice, concise, idiomatic Ruby code will also be part of my course. And today’s blog post will be about my first tries to do that. Most of the tasks that I will be doing in the part can be found on [Exercism.io](http://exercism.io/). First, two tasks were fairly simple and I will not bother you with them. But the next one called Hamming exercise was where the real fun began. In that exercise, I was asked to create a method that returns a number of mutations between two DNA strands. For example, for DNAs “AGA” and “AGG” it should return 1. If you want to read more check out the [Readme](http://exercism.io/exercises/ruby/hamming/readme).

My first solution passed all the tests and used some methods that you can find in the Enumerable module. I think using those methods when writing Ruby makes code easier to read.
```language-ruby
class Hamming
  def self.compute(original_strand, copied_strand)
    raise ArgumentError if original_strand.length != copied_strand.length
    original_strand = original_strand.split(//)
    copied_strand = copied_strand.split(//)

    original_strand.keep_if.with_index{ |x, i| x != copied_strand[i]}.count
  end
end
```

Arkency members checked it and Andrzej commented on it telling me that this solution looks ok if we treat DNA strands as simple strings and nothing more. And that my solution doesn't have any information about the domain. After couple of iterations I have created solution that looks like this:<commit_msg>Fix typo in Hamming<commit_after>---
layout: post
title: Hamming exercise
---

When you try to become web developer there are obvious things you need to learn. HTML is the foundation of each website, so you learn that. Then you start to think that it would be nice if the website looked just a bit better and you learn CSS. Then you figure out you need some JS to make it more dynamic and some backend framework and in my case you start to learn Ruby on Rails. But, there is also one more important part, which shouldn't be neglected if you aspire to become good programmer someday. We should learn how to write clean code and in the case of using objective oriented language how to write good OOP code.

[Arkency](http://blog.arkency.com) knows that and they also live by DDD. When I talked to [<NAME>](https://twitter.com/andrzejkrzywda) he explained that learning how to write nice, concise, idiomatic Ruby code will also be part of my course. And today’s blog post will be about my first tries to do that. Most of the tasks that I will be doing in the part can be found on [Exercism.io](http://exercism.io/). First, two tasks were fairly simple and I will not bother you with them. But the next one called Hamming exercise was where the real fun began. In that exercise, I was asked to create a method that returns a number of mutations between two DNA strands. For example, for DNAs “AGA” and “AGG” it should return 1. If you want to read more check out the [Readme](http://exercism.io/exercises/ruby/hamming/readme).

My first solution passed all the tests and used some methods that you can find in the Enumerable module. I think using those methods when writing Ruby makes code easier to read.
```language-ruby
class Hamming
  def self.compute(original_strand, copied_strand)
    raise ArgumentError if original_strand.length != copied_strand.length
    original_strand = original_strand.split(//)
    copied_strand = copied_strand.split(//)

    original_strand.keep_if.with_index{ |x, i| x != copied_strand[i]}.count
  end
end
```

Arkency members checked it and Andrzej commented on it telling me that this solution looks ok if we treat DNA strands as simple strings and nothing more. And that my solution doesn't have any information about the domain. After couple of iterations I have created solution that looks like this:
{'fraction_non_alphanumeric': 0.054424683951146344, 'fraction_numerical': 0.00042854081851296334, 'mean_word_length': 4.1866666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4983200', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1174, 'n_words': 722}