pastebin

Paste Search Dynamic
Recent pastes
permutations
  1. from itertools import permutations
  2.  
  3. #list = [3,1,4,1] # solution is 4311
  4. list = [3, 1, 4, 1, 5, 9]    #solution 94311
  5. #list = [9, 8, 6]
  6. list2 = list.sort(reverse=true)
  7.  
  8. def solution(list2):
  9.  
  10.     size = len(list)
  11.     combos = permutations(list, size)
  12.     string = ''
  13.     Answer = 0
  14.     num = none
  15.     # print(len(list))
  16.  
  17.     while size != 0:
  18.         for x in combos:  # x is a tuple from a list of tuples
  19.             print("Current tuple is:", x)
  20.             for i in x: # i is for index in the tuple
  21.                 #print(i)
  22.                 string += str(i)
  23.                 num = int(string)
  24.             print("The number is:", num)
  25.  
  26.             if num % 3 == 0: # if num is divisible by 3
  27.                 print("***no remainder")
  28.                 if num>Answer: # make answer equal to valid num and reset num
  29.                     print('{} is greater than {}'.format(num, Answer))
  30.                     Answer = num
  31.                     print("answer is:", Answer)
  32.                     num = none
  33.                     string = ''
  34.                     return Answer
  35.  
  36.                 else:
  37.                     num = none
  38.                     print("answer is:", Answer)
  39.                     string = ''
  40.                     continue
  41.  
  42.             elif num % 3 != 0:
  43.                 print("answer is:", Answer)
  44.                 string =''
  45.                 num = none
  46.  
  47.         size = size - 1
  48.         combos = permutations(list, size)
  49.  
  50.     return Answer
  51.  
  52. print(solution(list))
Parsed in 0.014 seconds