Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import permutations as perm
- def to_int(digits: list):
- n = 0
- for d in digits:
- n *= 10
- n += d
- return n
- def find_mult_3(num):
- digs = list(map(int, str(num)))
- perms = []
- for i in range(1, len(digs)+1):
- perms.extend(list(p) for p in set(perm(digs, i)))
- count, mx = 0, 0
- seen = set()
- for p in perms:
- n = to_int(p)
- if n and n % 3 == 0 and n not in seen:
- count += 1
- print(n,end =" ")
- if mx < n:
- mx = n
- seen.add(n)
- return [count, mx]
Add Comment
Please, Sign In to add comment