Advertisement
guyk

Tre like siffer

Jun 7th, 2023
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. from typing import List
  2.  
  3. def tokenize(perm : int) -> List[int]:
  4.     s = "{:05d}".format(perm)
  5.     a = s[0:1]
  6.     b = s[1:2]
  7.     c = s[2:3]
  8.     d = s[3:4]
  9.     e = s[4:5]
  10.     return [a,b,c,d,e]
  11.  
  12. def check_perm(perm : int) -> bool:
  13.     [a, b, c, d, e] = tokenize(perm)
  14.     if a == b and b == c and c != d:
  15.         return True
  16.     if a != b and b == c and c == d and d != e:
  17.         return True
  18.     if b != c and c == d and d == e:
  19.         return True
  20.     return False
  21.  
  22. combinations = []
  23. for i in range(1, 99999):
  24.     if check_perm(i):
  25.         combinations.append(i)
  26.  
  27. print(f'Fant {len(combinations)} kombinasjoner')
  28.  
  29. combinatorial = (10 * 9 * 10) + (10 * 9 * 9) + (10 * 9 * 10)
  30. print(f'Kombinatorisk lΓΈsning: {combinatorial}')
  31. print(f'Sannsynlighet: {combinatorial/100000}')
  32.  
  33. print('Alle kombinasjoner:')
  34. for c in combinations:
  35.     print("{:05d}".format(c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement