summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn1c00o <git.n1c00o@gmail.com>2021-10-12 21:53:27 +0200
committern1c00o <git.n1c00o@gmail.com>2021-10-12 21:53:27 +0200
commit19868f2d99212f532da95344cbbc9a5fc1fc74a3 (patch)
tree3043fc39e0edd8fab2f6f654ec45ef842a9c9cf7
parentf551a3af808e5b89b8744b8b3d77dee08ae63ce9 (diff)
Start solution, with explainations
-rw-r--r--bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py38
-rw-r--r--bringing-a-gun-to-a-trainer-fight/solution.py14
2 files changed, 36 insertions, 16 deletions
diff --git a/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py b/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py
index 71ecfe3..9dd6530 100644
--- a/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py
+++ b/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py
@@ -2,9 +2,7 @@ from math import sqrt
def norm(vec):
- """
- Return the norm of a vector
- """
+ # norm of a vector AB = distance between A and B = sqrt((xb - xa)**2 + (yb - ya)**2)
return sqrt(vec[0]**2 + vec[1]**2)
@@ -33,6 +31,40 @@ def solution(dimensions, your_position, trainer_position, distance):
# After making our mirrors and getting our vectors, we calculate the norm of these and if the norm is lesser than distance
# then it is a valid one
+ # get mirrors
+ mirrors = []
+ # todo
+
+ # calculate vectors using our mirrors and inverting coordinates on a mirror
+ vectors = []
+ # todo
+
+ # validate our vectors
+ # Valid vectors norms are lesser or equal to distance (constraints of beam)
+ # Valid vectors aren't colinear to shortest_vec (because if it is,
+ # either the beam will go through trainer before reaching the mirrored trainer,
+ # either the beam will bounce on the wall and touch yourself before reaching the trainer)
num_valid_vec = 0
+ for vec in vectors:
+ # if the vector equals shortest_vec, we avoid any computation on it
+ if vec == shortest_vec:
+ num_valid_vec += 1
+ continue
+
+ # Check if the norm of the vector <= distance or not
+ if norm(vec) > distance:
+ continue
+
+ # verify the vector is not colinear with shortest_vec
+ # Two vectors (here u and v) are colinears if there is a real number k we can use to write u = kv
+ # In other term, they are colinears if there is a relation of proportionality between vector's coordinates
+ k = shortest_vec[0] / vec[0]
+ if vec[1] * k == shortest_vec[1]:
+ # if true, then vectors are colinear
+ continue
+
+ # if the vector passes our tests, then it is valid
+ num_valid_vec += 1
+
return num_valid_vec
diff --git a/bringing-a-gun-to-a-trainer-fight/solution.py b/bringing-a-gun-to-a-trainer-fight/solution.py
index 36c45db..7eb69e2 100644
--- a/bringing-a-gun-to-a-trainer-fight/solution.py
+++ b/bringing-a-gun-to-a-trainer-fight/solution.py
@@ -1,14 +1,2 @@
-import math
-
-
-def get_distance(vec):
- return math.sqrt(vec[0]**2 + vec[1]**2)
-
-
def solution(dimensions, your_position, trainer_position, distance):
- # Verify that we can reach the trainer
- dist_to_trainer = get_distance(
- (trainer_position[0] - your_position[0], trainer_position[1] - your_position[10]))
- if dist_to_trainer > distance:
- # Unreachable
- return 0
+ # Your code here