You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
412 B
16 lines
412 B
class Hamming { |
|
|
|
def distance(strand1, strand2) { |
|
if (strand1.empty && strand2.empty) { |
|
0 |
|
} else if (strand1.size() != strand2.size()) { |
|
throw new ArithmeticException() |
|
} else { |
|
[strand1.chars, strand2.chars] |
|
.transpose() |
|
.collect { record -> record[0] == record[1]? 0: 1 } |
|
.sum() |
|
} |
|
} |
|
|
|
}
|
|
|