> For the complete documentation index, see [llms.txt](https://anton-veselskyi.gitbook.io/codding-problems-solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anton-veselskyi.gitbook.io/codding-problems-solutions/codewars/7-kyu/complementary-dna.md).

# Complementary DNA

## [Complementary DNA](https://www.codewars.com/kata/554e4a2f232cdd87d9000038)

Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.

If you want to know more <http://en.wikipedia.org/wiki/DNA>

In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have a 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).

More similar exercise are found here <http://rosalind.info/problems/list-view/> (source)

```python
DNA_strand ("ATTGC") # return "TAACG"

DNA_strand ("GTAT") # return "CATA"
```

```javascript
DNAStrand ("ATTGC") // return "TAACG"

DNAStrand ("GTAT") // return "CATA"
```

```typescript
dnaStrand("ATTGC") // return "TAACG"

dnaStrand("GTAT") // return "CATA"
```

```csharp
MakeComplement("ATTGC") => "TAACG"

MakeComplement("GTAT") => "CATA"
```

```php
DNA_strand("ATTGC") // returns "TAACG"
DNA_strand("GTAT") // returns "CATA"
```

```ruby
DNA_strand ("ATTGC") # return "TAACG"

DNA_strand ("GTAT") # return "CATA"
```

```
dna_strand("ATTGC") # return "TAACG"

dna_strand("GTAT") # return "CATA"
```

```java
DnaStrand.makeComplement("ATTGC") // return "TAACG"

DnaStrand.makeComplement("GTAT") // return "CATA"
```

```kotlin
makeComplement("ATTGC") // return "TAACG"

makeComplement("GTAT") // return "CATA"
```

```haskell
dnaStrand []        `shouldBe` []
dnaStrand [A,T,G,C] `shouldBe` [T,A,C,G]
dnaStrand [G,T,A,T] `shouldBe` [C,A,T,A]
dnaStrand [A,A,A,A] `shouldBe` [T,T,T,T]
```

```
(is (= (dna-strand "ATTGC") "TAACG"))

(is (= (dna-strand "GTAT") "CATA"))
```

```c
dna_strand("ATTGC") /* return "TAACG" */
dna_strand("GTAT")  /* return "CATA"  */
```

```go
DNAStrand("ATTGC") // returns "TAACG"

DNAStrand("GTAT") // returns "CATA"
```

```rust
dna_strand("ATTGC") // returns "TAACG"
dna_strand("GTAT")  // returns "CATA"
```

```julia
dnastrand("ATTGC") # returns "TAACG"
dnastrand("GTAT")  # returns "CATA"
```

```
dna_strand("ATTGC") == "TAACG"
dna_strand("GTAT") == "CATA"
```

## Solutions

### 🐍 Python

```python
def DNA_strand(dna):
    return "".join(['T' if v == 'A' else 'A' if v == 'T' else 'G' if v == 'C' else 'C' for v in dna])
```
