-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6b57732
commit 89015d1
Showing
5 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
# [[BUG] XCOM-241: Genome mapper freezes](https://www.codewars.com/kata/bug-xcom-241-genome-mapper-freezes "https://www.codewars.com/kata/64d55f26529cad3a7a8c6752") | ||
|
||
You are an intern working in the software development department of the X-COM agency, responsible for fighting off a large-scale invasion of extraterrestrials. Today you found following ticket at the top of your backlog: | ||
|
||
----- | ||
|
||
## [XCOM-241] Genome mapper freezes on long DNA strands | ||
|
||
|
||
**Type:** Bug 🪳 | ||
**Priority:** Critical 🔥 | ||
**Component:** Genome mapper | ||
**Reporter:** `ikleiner` | ||
**Type:** Bug 🪳 | ||
**Priority:** Critical 🔥 | ||
**Component:** Genome mapper | ||
**Reporter:** `ikleiner` | ||
**Assignee:** _Assigned to you_ | ||
|
||
|
||
### Description of the bug | ||
|
||
The genome mapper created by software engineers from Black Mesa Research Facility freezes and produces no output when mapping long strands of alien DNA sampled from recently obtained body of sectoid psionic. | ||
The genome mapper created by software engineers from Black Mesa Research Facility freezes and produces no output when mapping long strands | ||
of alien DNA sampled from recently obtained body of sectoid psionic. | ||
|
||
However, the mapper does not hang for short samples simulating more primitive alien life forms like silacoids, celatids, and mutons. | ||
|
||
Only after the performance issue gets fixed, the research team will be able to move to the second stage of tests and verify correctness of performed mapping. | ||
|
||
Only after the performance issue gets fixed, the research team will be able to move to the second stage of tests and verify correctness of | ||
performed mapping. | ||
|
||
### Additional info | ||
|
||
**Strand format:** SLC (singly-linked chain of alien DNA nucleobases). Nucleobases are represented as following records: | ||
|
||
```java | ||
public record SlcBase(SlcBase next, char nucleobase) {} | ||
public record SlcBase(SlcBase next, char nucleobase) { | ||
|
||
} | ||
``` | ||
|
||
**Mapping:** `HOPE-LUNA` mapping (`H` maps to `L`, `O` to `U`, `P` to `N`, `E` to `A`, and vice versa). Lowercase inputs map to uppercase output. | ||
**Mapping:** `HOPE-LUNA` mapping (`H` maps to `L`, `O` to `U`, `P` to `N`, `E` to `A`, and vice versa). Lowercase inputs map to uppercase | ||
output. | ||
**Throughput:** It's necessary to be able to process hundreds of strands of ~200k nucleobases. | ||
|
||
|
||
### Notes | ||
|
||
This bug is CRITICAL and must be fixed ASAP! The body of the sectoid psionic is going to decompose in three days and it will be impossible to use it for further research! | ||
This bug is CRITICAL and must be fixed ASAP! The body of the sectoid psionic is going to decompose in three days, and it will be impossible | ||
to use it for further research! |
14 changes: 14 additions & 0 deletions
14
kata/7-kyu/bug-xcom-241-genome-mapper-freezes/main/xcom/dna/mapping/HopeLunaMapper.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package xcom.dna.mapping; | ||
|
||
import static java.util.stream.Stream.iterate; | ||
|
||
import java.util.Objects; | ||
|
||
class HopeLunaMapper { | ||
String mapStrand(SlcBase base) { | ||
return iterate(base, Objects::nonNull, SlcBase::next) | ||
.mapToInt(slc -> "_E___A__L___H_PUN____O".charAt(slc.nucleobase() & 31)) | ||
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) | ||
.toString(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
kata/7-kyu/bug-xcom-241-genome-mapper-freezes/main/xcom/dna/mapping/SlcBase.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package xcom.dna.mapping; | ||
|
||
record SlcBase(SlcBase next, char nucleobase) {} |
33 changes: 33 additions & 0 deletions
33
kata/7-kyu/bug-xcom-241-genome-mapper-freezes/test/xcom/dna/mapping/HopeLunaMapperTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package xcom.dna.mapping; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class HopeLunaMapperTest { | ||
|
||
private final HopeLunaMapper mapper = new HopeLunaMapper(); | ||
|
||
@Test | ||
void nothing() { | ||
assertEquals("", mapper.mapStrand(null)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 100, 20000}) | ||
void sample(int repeat) { | ||
SlcBase source = toStrand("LUNAHOPE".repeat(repeat)); | ||
assertEquals("HOPELUNA".repeat(repeat), mapper.mapStrand(source)); | ||
} | ||
|
||
private SlcBase toStrand(String str) { | ||
SlcBase current = null; | ||
int len = str.length(); | ||
for (int i = 0; i < len; ++i) { | ||
current = new SlcBase(current, str.charAt(len - i - 1)); | ||
} | ||
return current; | ||
} | ||
} |
This file contains 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