Created
June 2, 2017 18:55
-
-
Save michellejanosi/2b3e158346766edc4f6fc5cc1e2cba23 to your computer and use it in GitHub Desktop.
Hamming in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hamming | |
| def self.compute(a, b) | |
| raise ArgumentError if a.length != b.length | |
| counter = 0 | |
| a.split('').each_with_index do |item, index| | |
| if a[index] != b[index] | |
| counter += 1 | |
| end | |
| end | |
| counter | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment