summaryrefslogtreecommitdiff
path: root/please-pass-the-coded-messages/solution.py
diff options
context:
space:
mode:
Diffstat (limited to 'please-pass-the-coded-messages/solution.py')
-rw-r--r--please-pass-the-coded-messages/solution.py28
1 files changed, 27 insertions, 1 deletions
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