Guest User

Untitled

a guest
Aug 29th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. from itertools import permutations as perm
  2. def to_int(digits: list):
  3.     n = 0
  4.     for d in digits:
  5.         n *= 10
  6.         n += d
  7.     return n
  8.  
  9. def find_mult_3(num):
  10.     digs = list(map(int, str(num)))
  11.     perms = []
  12.     for i in range(1, len(digs)+1):
  13.         perms.extend(list(p) for p in set(perm(digs, i)))
  14.    
  15.     count, mx = 0, 0
  16.     seen = set()
  17.     for p in perms:
  18.         n = to_int(p)
  19.         if n and n % 3 == 0 and n not in seen:
  20.             count += 1
  21.             print(n,end =" ")
  22.             if mx < n:
  23.                 mx = n
  24.             seen.add(n)
  25.  
  26.     return [count, mx]
Add Comment
Please, Sign In to add comment