summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn1c00o <git.n1c00o@gmail.com>2021-10-12 20:30:54 +0200
committern1c00o <git.n1c00o@gmail.com>2021-10-12 20:30:54 +0200
commitf551a3af808e5b89b8744b8b3d77dee08ae63ce9 (patch)
tree1e0fea2a6fbb800d691826b2128ea9f83e9ea383
parent412d9f7739404b734e03c090b07e4ddfd8a1ee3f (diff)
Move my solution into a specific folder
-rw-r--r--bringing-a-gun-to-a-trainer-fight/n1c00o/README.md1
-rw-r--r--bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py38
-rw-r--r--find-the-access-codes/n1c00o/solution.py17
-rw-r--r--find-the-access-codes/solution.py17
-rw-r--r--free-the-bunny-workers/n1c00o/solution.py14
-rw-r--r--free-the-bunny-workers/solution.py14
-rw-r--r--fuel-injection-perfection/n1c00o/solution.py38
-rw-r--r--fuel-injection-perfection/solution.py40
-rw-r--r--numbers-station-coded-messages/n1c00o/solution.py11
-rw-r--r--numbers-station-coded-messages/solution.py11
-rw-r--r--please-pass-the-coded-messages/n1c00o/solution.py28
-rw-r--r--please-pass-the-coded-messages/solution.py28
-rw-r--r--skipping-work/n1c00o/solutions.py (renamed from skipping-work/solutions.py)0
-rw-r--r--skipping-work/solution.py2
-rw-r--r--the-grandest-staircase-of-them-all/n1c00o/solution.py7
-rw-r--r--the-grandest-staircase-of-them-all/solution.py7
16 files changed, 163 insertions, 110 deletions
diff --git a/bringing-a-gun-to-a-trainer-fight/n1c00o/README.md b/bringing-a-gun-to-a-trainer-fight/n1c00o/README.md
new file mode 100644
index 0000000..cc370ec
--- /dev/null
+++ b/bringing-a-gun-to-a-trainer-fight/n1c00o/README.md
@@ -0,0 +1 @@
+# n1c00o
diff --git a/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py b/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py
new file mode 100644
index 0000000..71ecfe3
--- /dev/null
+++ b/bringing-a-gun-to-a-trainer-fight/n1c00o/solution.py
@@ -0,0 +1,38 @@
+from math import sqrt
+
+
+def norm(vec):
+ """
+ Return the norm of a vector
+ """
+ return sqrt(vec[0]**2 + vec[1]**2)
+
+
+def solution(dimensions, your_position, trainer_position, distance):
+ # shortest vector between you and the trainer
+ shortest_vec = [trainer_position[0] - your_position[0],
+ trainer_position[1] - your_position[1]]
+ shortest_vec_norm = norm(shortest_vec)
+
+ # If the norm of the sortest vector between you and the trainer is greater than distance,
+ # then there is no solution
+ if shortest_vec_norm > distance:
+ return 0
+ # if the norm of the shortest vector is equal to the distance, then there is only this solution
+ elif shortest_vec_norm == distance:
+ return 1
+
+ # Beginning of the algorithm...
+ # The goal is to mirror the room given thanks to dimensions and then calculate all vectors between `your` in the original room
+ # and the replicated trainer.
+ # We make replicas using x, y, d and e where
+ # x is the horizontal axis
+ # y is the vertical axis
+ # d is the line parallel to x which goes through (0; dimensions[1]) to (dimensions[0]; dimensions[1])
+ # e is the line parallel to y which goes through (dimensions[0]; 0) to (dimensions[0]; dimensions[1])
+ # 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
+
+ num_valid_vec = 0
+
+ return num_valid_vec
diff --git a/find-the-access-codes/n1c00o/solution.py b/find-the-access-codes/n1c00o/solution.py
new file mode 100644
index 0000000..b0daf44
--- /dev/null
+++ b/find-the-access-codes/n1c00o/solution.py
@@ -0,0 +1,17 @@
+def solution(array):
+ if len(array) < 3:
+ return 0
+
+ solutions = [0] * len(array)
+ found = 0
+
+ for i in range(len(array)):
+ for j in range(i):
+ if array[i] % array[j] == 0:
+ solutions[i] += 1
+ found += solutions[j]
+ return found
+
+
+print(solution([1, 2, 3, 4, 5, 6]), "should equal", 3)
+print(solution([1, 1, 1]), "should equal", 1)
diff --git a/find-the-access-codes/solution.py b/find-the-access-codes/solution.py
index b0daf44..213ac44 100644
--- a/find-the-access-codes/solution.py
+++ b/find-the-access-codes/solution.py
@@ -1,17 +1,2 @@
def solution(array):
- if len(array) < 3:
- return 0
-
- solutions = [0] * len(array)
- found = 0
-
- for i in range(len(array)):
- for j in range(i):
- if array[i] % array[j] == 0:
- solutions[i] += 1
- found += solutions[j]
- return found
-
-
-print(solution([1, 2, 3, 4, 5, 6]), "should equal", 3)
-print(solution([1, 1, 1]), "should equal", 1)
+ # Your code here
diff --git a/free-the-bunny-workers/n1c00o/solution.py b/free-the-bunny-workers/n1c00o/solution.py
new file mode 100644
index 0000000..66ca6e5
--- /dev/null
+++ b/free-the-bunny-workers/n1c00o/solution.py
@@ -0,0 +1,14 @@
+from itertools import combinations
+
+
+def solution(num_buns, num_required):
+ c = list(combinations(range(num_buns), num_buns - (num_required - 1)))
+ res = []
+
+ for bunny in range(num_buns):
+ res.append([k for k, b in enumerate(c) if bunny in b])
+
+ return res
+
+
+print(solution(5, 3))
diff --git a/free-the-bunny-workers/solution.py b/free-the-bunny-workers/solution.py
index 66ca6e5..006515e 100644
--- a/free-the-bunny-workers/solution.py
+++ b/free-the-bunny-workers/solution.py
@@ -1,14 +1,2 @@
-from itertools import combinations
-
-
def solution(num_buns, num_required):
- c = list(combinations(range(num_buns), num_buns - (num_required - 1)))
- res = []
-
- for bunny in range(num_buns):
- res.append([k for k, b in enumerate(c) if bunny in b])
-
- return res
-
-
-print(solution(5, 3))
+ # Your code here
diff --git a/fuel-injection-perfection/n1c00o/solution.py b/fuel-injection-perfection/n1c00o/solution.py
new file mode 100644
index 0000000..388a739
--- /dev/null
+++ b/fuel-injection-perfection/n1c00o/solution.py
@@ -0,0 +1,38 @@
+def solution(str_n):
+ # 3 possibles operations:
+ # - Add one fuel
+ # - Remove one fuel
+ # - Divide fuel by 2 (allowed only if fuel is an even number)
+ fuel = int(str_n)
+ actions = 0
+
+ # Execute until we get 1 fuel remaining
+ while fuel != 1:
+ # If fuel is not an even number, we need to add or remove one fuel
+ if fuel % 2 != 0:
+ # We have to check if it is more interesting to add or remove one fuel, depending on the result of (fuel + 1) % 2 and (fuel - 1)
+ # i.e. 13 -> Adding 1 = 14 ; 14 // 2 = 7 ; we'd need to update 7 to get an even number
+ # 13 -> Removing 1 = 12 ; 12 // 2 = 6 ; we wouldn't need to add change 6
+
+ # If removing one is more efficient
+ if ((fuel - 1) // 2) % 2 == 0:
+ fuel -= 1
+ actions += 1
+ # Exception! If it results in 2, then it is more efficient to go from 3 to 2
+ elif fuel - 1 == 2:
+ fuel -= 1
+ actions += 1
+ # if not, we add one
+ else:
+ fuel += 1
+ actions += 1
+
+ # Consume fuel
+ fuel //= 2
+ actions += 1
+
+ return actions
+
+
+print(solution('4'), "should equal 2")
+print(solution('15'), "should equal 5")
diff --git a/fuel-injection-perfection/solution.py b/fuel-injection-perfection/solution.py
index 388a739..744b41d 100644
--- a/fuel-injection-perfection/solution.py
+++ b/fuel-injection-perfection/solution.py
@@ -1,38 +1,2 @@
-def solution(str_n):
- # 3 possibles operations:
- # - Add one fuel
- # - Remove one fuel
- # - Divide fuel by 2 (allowed only if fuel is an even number)
- fuel = int(str_n)
- actions = 0
-
- # Execute until we get 1 fuel remaining
- while fuel != 1:
- # If fuel is not an even number, we need to add or remove one fuel
- if fuel % 2 != 0:
- # We have to check if it is more interesting to add or remove one fuel, depending on the result of (fuel + 1) % 2 and (fuel - 1)
- # i.e. 13 -> Adding 1 = 14 ; 14 // 2 = 7 ; we'd need to update 7 to get an even number
- # 13 -> Removing 1 = 12 ; 12 // 2 = 6 ; we wouldn't need to add change 6
-
- # If removing one is more efficient
- if ((fuel - 1) // 2) % 2 == 0:
- fuel -= 1
- actions += 1
- # Exception! If it results in 2, then it is more efficient to go from 3 to 2
- elif fuel - 1 == 2:
- fuel -= 1
- actions += 1
- # if not, we add one
- else:
- fuel += 1
- actions += 1
-
- # Consume fuel
- fuel //= 2
- actions += 1
-
- return actions
-
-
-print(solution('4'), "should equal 2")
-print(solution('15'), "should equal 5")
+def solution(n):
+ # Your code here
diff --git a/numbers-station-coded-messages/n1c00o/solution.py b/numbers-station-coded-messages/n1c00o/solution.py
new file mode 100644
index 0000000..8c2f717
--- /dev/null
+++ b/numbers-station-coded-messages/n1c00o/solution.py
@@ -0,0 +1,11 @@
+def solution(l, t):
+ for start_i in range(len(l)):
+ sum = 0
+
+ for curr_i in range(start_i, len(l)):
+ sum += l[curr_i]
+
+ if sum == t:
+ return [start_i, curr_i]
+
+ return [-1, -1]
diff --git a/numbers-station-coded-messages/solution.py b/numbers-station-coded-messages/solution.py
index 8c2f717..c127144 100644
--- a/numbers-station-coded-messages/solution.py
+++ b/numbers-station-coded-messages/solution.py
@@ -1,11 +1,2 @@
def solution(l, t):
- for start_i in range(len(l)):
- sum = 0
-
- for curr_i in range(start_i, len(l)):
- sum += l[curr_i]
-
- if sum == t:
- return [start_i, curr_i]
-
- return [-1, -1]
+ # Your code here
diff --git a/please-pass-the-coded-messages/n1c00o/solution.py b/please-pass-the-coded-messages/n1c00o/solution.py
new file mode 100644
index 0000000..91fc5ca
--- /dev/null
+++ b/please-pass-the-coded-messages/n1c00o/solution.py
@@ -0,0 +1,28 @@
+import itertools
+
+
+def solution(l):
+ res = 0
+
+ # Get all the permutations of the list, without duplicates
+ for r in range(0, len(l) + 1, 1):
+
+ for i in itertools.permutations(l, r):
+
+ # ignore the empty set
+ if i == ():
+ continue
+
+ # now we need to convert tuples into an int
+ # such as (1, 2, 3) become 123
+ num = int("".join(str(x) for x in i))
+
+ # now we check if the number is divisible by 3
+ # and greater than the latest divisible
+ if num % 3 == 0 and num > res:
+ res = num
+ return res
+
+
+print(solution([3, 1, 4, 1])) # == 4311
+print(solution([3, 1, 4, 1, 5, 9])) # == 94311
diff --git a/please-pass-the-coded-messages/solution.py b/please-pass-the-coded-messages/solution.py
index 91fc5ca..586841e 100644
--- a/please-pass-the-coded-messages/solution.py
+++ b/please-pass-the-coded-messages/solution.py
@@ -1,28 +1,2 @@
-import itertools
-
-
def solution(l):
- res = 0
-
- # Get all the permutations of the list, without duplicates
- for r in range(0, len(l) + 1, 1):
-
- for i in itertools.permutations(l, r):
-
- # ignore the empty set
- if i == ():
- continue
-
- # now we need to convert tuples into an int
- # such as (1, 2, 3) become 123
- num = int("".join(str(x) for x in i))
-
- # now we check if the number is divisible by 3
- # and greater than the latest divisible
- if num % 3 == 0 and num > res:
- res = num
- return res
-
-
-print(solution([3, 1, 4, 1])) # == 4311
-print(solution([3, 1, 4, 1, 5, 9])) # == 94311
+ # Your code here
diff --git a/skipping-work/solutions.py b/skipping-work/n1c00o/solutions.py
index 31cda09..31cda09 100644
--- a/skipping-work/solutions.py
+++ b/skipping-work/n1c00o/solutions.py
diff --git a/skipping-work/solution.py b/skipping-work/solution.py
new file mode 100644
index 0000000..db1aa96
--- /dev/null
+++ b/skipping-work/solution.py
@@ -0,0 +1,2 @@
+def solution(x, y):
+ # Your code here
diff --git a/the-grandest-staircase-of-them-all/n1c00o/solution.py b/the-grandest-staircase-of-them-all/n1c00o/solution.py
new file mode 100644
index 0000000..d4e5499
--- /dev/null
+++ b/the-grandest-staircase-of-them-all/n1c00o/solution.py
@@ -0,0 +1,7 @@
+def solution(n):
+ t = [1] + [0]*n
+ for s in range(1, n + 1):
+ for h in range(n, s - 1, -1):
+ t[h] += t[h - s]
+
+ return t[-1] - 1
diff --git a/the-grandest-staircase-of-them-all/solution.py b/the-grandest-staircase-of-them-all/solution.py
index d4e5499..744b41d 100644
--- a/the-grandest-staircase-of-them-all/solution.py
+++ b/the-grandest-staircase-of-them-all/solution.py
@@ -1,7 +1,2 @@
def solution(n):
- t = [1] + [0]*n
- for s in range(1, n + 1):
- for h in range(n, s - 1, -1):
- t[h] += t[h - s]
-
- return t[-1] - 1
+ # Your code here