Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Oct 12, 2024
1 parent 6b57732 commit 89015d1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 17 deletions.
32 changes: 15 additions & 17 deletions kata/7-kyu/bug-xcom-241-genome-mapper-freezes/README.md
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!
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package xcom.dna.mapping;

record SlcBase(SlcBase next, char nucleobase) {}
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;
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- [Breaking chocolate problem](breaking-chocolate-problem)
- [Broken sequence](broken-sequence)
- [Bubblesort Once](bubblesort-once)
- [[BUG] XCOM-241: Genome mapper freezes](bug-xcom-241-genome-mapper-freezes)
- [Build a square](build-a-square)
- [Building blocks](building-blocks)
- [Bulls and Cows](bulls-and-cows)
Expand Down

0 comments on commit 89015d1

Please sign in to comment.