DAY 17
1

## Day17 - Codewars 刷題

``````In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).
``````
``````def DNA_strand(dna)
end

Test.assert_equals(DNA_strand("AAAA"),"TTTT","String AAAA is")
Test.assert_equals(DNA_strand("ATTGC"),"TAACG","String ATTGC is")
Test.assert_equals(DNA_strand("GTAT"),"CATA","String GTAT is")
``````
``````In this kata, you must create a digital root function.

A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.
``````
``````def digital_root(n)
# ...
end

Test.assert_equals( digital_root(16), 7 )
Test.assert_equals( digital_root(456), 6 )
``````

``````# Complementary DNA
def DNA_strand(dna)
dna.tr('ATCG', 'TAGC')
end

# Sum of Digits / Digital Root
def digital_root(n)
n < 10 ? n : digital_root( n / 10  + n % 10)
end
``````