Skip to content

Commit 8fb2030

Browse files
JakubDotPygithub-actions[bot]
authored andcommitted
Automated update
1 parent e3ebb1e commit 8fb2030

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

output/dna_sequence_tester.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Kata - DNA Sequence Tester
2+
3+
completed at: 2024-05-03 14:01:58
4+
by: Jakub Červinka
5+
6+
DNA is a biomolecule that carries genetic information. It is composed of four different building blocks, called nucleotides: adenine (A), thymine (T), cytosine (C) and guanine (G). Two DNA strands join to form a double helix, whereby the nucleotides of one strand bond to the nucleotides of the other strand at the corresponding positions. The bonding is only possible if the nucleotides are complementary: A always pairs with T, and C always pairs with G.
7+
8+
Due to the asymmetry of the DNA, every DNA strand has a direction associated with it. The two strands of the double helix run in opposite directions to each other, which we refer to as the 'up-down' and the 'down-up' directions.
9+
10+
Write a function `checkDNA` that takes in two DNA sequences as strings, and checks if they are fit to form a fully complementary DNA double helix. The function should return a Boolean `true` if they are complementary, and `false` if there is a sequence mismatch (Example 1 below).
11+
12+
Note:
13+
14+
- All sequences will be of non-zero length, and consisting only of `A`, `T`, `C` and `G` characters.
15+
- All sequences **will be given in the up-down direction**.
16+
- The two sequences to be compared can be of different length. If this is the case and one strand is entirely bonded by the other, and there is no sequence mismatch between the two (Example 2 below), your function should still return `true`.
17+
- If both strands are only partially bonded (Example 3 below), the function should return `false`.
18+
19+
Example 1:
20+
```javascript
21+
seq1 = 'GTCTTAGTGTAGCTATGCATGC'; // NB up-down
22+
seq2 = 'GCATGCATAGCTACACTACGAC'; // NB up-down
23+
24+
checkDNA (seq1, seq2);
25+
// --> false
26+
27+
// Because there is a sequence mismatch at position 4:
28+
// (seq1) up-GTCTTAGTGTAGCTATGCATGC-down
29+
// ||| ||||||||||||||||||
30+
// (seq2) down-CAGCATCACATCGATACGTACG-up
31+
```
32+
33+
Example 2:
34+
35+
```javascript
36+
seq1 = 'GCGCTGCTAGCTGATCGA'; // NB up-down
37+
seq2 = 'ACGTACGATCGATCAGCTAGCAGCGCTAC'; // NB up-down
38+
39+
checkDNA (seq1, seq2);
40+
// --> true
41+
42+
// Because one strand is entirely bonded by the other:
43+
// (seq1) up-GCGCTGCTAGCTGATCGA-down
44+
// ||||||||||||||||||
45+
// (seq2) down-CATCGCGACGATCGACTAGCTAGCATGCA-up
46+
```
47+
48+
Example 3:
49+
50+
```javascript
51+
seq1 = 'CGATACGAACCCATAATCG'; // NB up-down
52+
seq2 = 'CTACACCGGCCGATTATGG'; // NB up-down
53+
54+
checkDNA (seq1, seq2);
55+
// --> false
56+
57+
// Because both strands are only partially bonded:
58+
// (seq1) up-CGATACGAACCCATAATCG-down
59+
// |||||||||
60+
// (seq2) down-GGTATTAGCCGGCCACATC-up
61+
```
62+
63+
---
64+
#### If you enjoyed this kata, check out also my other DNA kata: [**Longest Repeated DNA Motif**](http://www.codewars.com/kata/longest-repeated-dna-motif)
65+
66+
"""
67+
68+
trans = str.maketrans("ACGT", "TGCA")
69+
70+
def check_DNA(s1, s2):
71+
s1, s2 = sorted((s1, s2), key=len)
72+
return s1 in s2[::-1].translate(trans)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Kata - Find the crossing ( graphic calculations )
2+
3+
completed at: 2024-05-03 13:34:17
4+
by: Jakub Červinka
5+
6+
## Description
7+
You are given four tuples. In each tuple there is coordinates x and y of a point. There is one and only one line, that goes through two points, so with four points you can have two lines: first and second tuple is two points of a first line, thirs and fourth tuple is two points of the second line. Your task is to find and return a tuple with x and y coordinates of lines crossing point.
8+
9+
Numbers can be positive as well as negative, integer or floats. Your answer shouldn't be rounded!!
10+
11+
Note, that if two lines are the same ( have infinite crossing points ) or parallel ( have no crossing points ), you will need to return ```None```.
12+
13+
![Example on graphic](https://justpaste.it/img/a6760541d86f232527c516f6882c28dc.png "Example on graphic")
14+
15+
## Examples
16+
``` python
17+
find_the_crossing((5,3), (10,4), (5,7.5), (10,7)) => (20, 6) #from the graphic above
18+
find_the_crossing((5,3), (10,4), (20,6), (0,2)) => -1 #edge case for two identical lines
19+
find_the_crossing((5,3), (10,4), (5,5), (10,6)) => -1 #edge case for two parallel lines
20+
```
21+
## Tests
22+
There will be example tests, random tests and tests on big numbers.
23+
24+
**Example tests** are pre programmed tests for debugging.
25+
26+
**Random tests** are generated randomly, where ```-1000 ≤ x ≤ 1100```. There is still will some with parallel and identical lines.
27+
28+
**Tests on big numbers** are random tests where ```-1000000000 ≤ x ≤ 1000000000```
29+
"""
30+
31+
import numpy as np
32+
33+
def find_the_crossing(a, b, c, d):
34+
s = np.vstack([a, b, c, d]) # s for stacked
35+
h = np.hstack((s, np.ones((4, 1)))) # h for homogeneous
36+
l1 = np.cross(h[0], h[1]) # get first line
37+
l2 = np.cross(h[2], h[3]) # get second line
38+
x, y, z = np.cross(l1, l2) # point of intersection
39+
if z == 0: # lines are parallel
40+
return None
41+
return (x/z, y/z)

0 commit comments

Comments
 (0)