SHARE
TWEET

Untitled

a guest Jan 11th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import itertools
  2. import copy
  3. a = [1,2,8,6]
  4. old_a = copy.deepcopy(a)
  5. pers = itertools.permutations(a,2)
  6. k =  list(pers)
  7. combined = []
  8. for i in k:
  9.         combined.append(int(str(i[0])+str(i[1])))
  10. combined.sort(reverse=True)
  11. print combined
  12. d1 = 0
  13. d2 = 0
  14. no = []
  15. found_d1 = False
  16. found_d2 = False
  17. while found_d1 == False or found_d2 == False:
  18.         a = copy.deepcopy(old_a)
  19.         pers = itertools.permutations(a,2)
  20.         k =  list(pers)
  21.         combined = []
  22.         for i in k:
  23.                 combined.append(int(str(i[0])+str(i[1])))
  24.         combined.sort(reverse=True)
  25.         old_comb = combined
  26.         for i in combined:
  27.                 if i < 24 and i not in no:
  28.                         d1 = i
  29.                         found_d1 = True
  30.                         break
  31.         if found_d1 == False:
  32.                 break
  33.         a.remove(d1/10)
  34.         a.remove(d1%10)
  35.         pers = itertools.permutations(a,2)
  36.         k =  list(pers)
  37.         combined = []
  38.         for i in k:
  39.                 combined.append(int(str(i[0])+str(i[1])))
  40.         combined.sort(reverse=True)
  41.         for i in combined:
  42.                 if i < 60:
  43.                         d2 = i
  44.                         found_d2 = True
  45.                         break
  46.         if found_d1 == True and found_d2 == False:
  47.                 no.append(d1)
  48.                 found_d1 = False
  49.  
  50. if found_d1 == False or found_d2 == False:
  51.         print "Not valid"
  52. else:
  53.         print d1
  54.         print d2
RAW Paste Data
Top