-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecomposeDoubleStrandDNAInto6ReadingFrames.kt
56 lines (50 loc) · 2.14 KB
/
DecomposeDoubleStrandDNAInto6ReadingFrames.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.smlnskgmail.jaman.codewarskotlin.kyu6
// https://www.codewars.com/kata/57519060f2dac7ec95000c8e
class DecomposeDoubleStrandDNAInto6ReadingFrames(
private val input: String
) {
@Suppress("MagicNumber", "ComplexMethod", "MaxLineLength")
fun solution(): String {
val firstFrame = input
.mapIndexed { index, c -> if ((index + 1) % 3 == 0) "$c " else c.toString() }
.joinToString("")
.trim()
val secondFrame = input
.mapIndexed { index, c -> if (index == 0 || index > 2 && (index + 3) % 3 == 0) "$c " else c.toString() }
.joinToString("")
.trim()
val thirdFrame = input
.mapIndexed { index, c -> if (index == 1 || index > 2 && (index + 5) % 3 == 0) "$c " else c.toString() }
.joinToString("")
.trim()
val reversedDNA = input
.reversed()
.map {
when (it) {
'A' -> 'T'
'T' -> 'A'
'C' -> 'G'
else -> 'C'
}
}
.joinToString("")
val firstFrameReversed = reversedDNA
.mapIndexed { index, c -> if ((index + 1) % 3 == 0) "$c " else c.toString() }
.joinToString("")
.trim()
val secondFrameReversed = reversedDNA
.mapIndexed { index, c -> if (index == 0 || index > 2 && (index + 3) % 3 == 0) "$c " else c.toString() }
.joinToString("")
.trim()
val thirdFrameReversed = reversedDNA
.mapIndexed { index, c -> if (index == 1 || index > 2 && (index + 5) % 3 == 0) "$c " else c.toString() }
.joinToString("")
.trim()
return "Frame 1: $firstFrame\n" +
"Frame 2: $secondFrame\n" +
"Frame 3: $thirdFrame\n\n" +
"Reverse Frame 1: $firstFrameReversed\n" +
"Reverse Frame 2: $secondFrameReversed\n" +
"Reverse Frame 3: $thirdFrameReversed"
}
}