diff options
| author | n1c00o <git.n1c00o@gmail.com> | 2021-10-06 21:53:35 +0200 |
|---|---|---|
| committer | n1c00o <git.n1c00o@gmail.com> | 2021-10-06 21:53:35 +0200 |
| commit | a97645d937123c87045ae381780f5379726a229b (patch) | |
| tree | 73396b28b00d254a34afc8f18ea87ec4d24c34c6 | |
| parent | d6af7a2c4f3342a69e1cd0507654d811dcbe11ee (diff) | |
Add working code for please-pass-the-coded-messages
| -rw-r--r-- | .vscode/settings.json | 5 | ||||
| -rw-r--r-- | please-pass-the-coded-messages/solution.py | 28 |
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 |
