summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn1c00o <git.n1c00o@gmail.com>2021-10-06 21:53:35 +0200
committern1c00o <git.n1c00o@gmail.com>2021-10-06 21:53:35 +0200
commita97645d937123c87045ae381780f5379726a229b (patch)
tree73396b28b00d254a34afc8f18ea87ec4d24c34c6
parentd6af7a2c4f3342a69e1cd0507654d811dcbe11ee (diff)
Add working code for please-pass-the-coded-messages
-rw-r--r--.vscode/settings.json5
-rw-r--r--please-pass-the-coded-messages/solution.py28
2 files changed, 32 insertions, 1 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..22b5a38
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,5 @@
+{
+ "cSpell.words": [
+ "curr"
+ ]
+}
diff --git a/please-pass-the-coded-messages/solution.py b/please-pass-the-coded-messages/solution.py
index 586841e..91fc5ca 100644
--- a/please-pass-the-coded-messages/solution.py
+++ b/please-pass-the-coded-messages/solution.py
@@ -1,2 +1,28 @@
+import itertools
+
+
def solution(l):
- # Your code here
+ 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