Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import List
- def tokenize(perm : int) -> List[int]:
- s = "{:05d}".format(perm)
- a = s[0:1]
- b = s[1:2]
- c = s[2:3]
- d = s[3:4]
- e = s[4:5]
- return [a,b,c,d,e]
- def check_perm(perm : int) -> bool:
- [a, b, c, d, e] = tokenize(perm)
- if a == b and b == c and c != d:
- return True
- if a != b and b == c and c == d and d != e:
- return True
- if b != c and c == d and d == e:
- return True
- return False
- combinations = []
- for i in range(1, 99999):
- if check_perm(i):
- combinations.append(i)
- print(f'Fant {len(combinations)} kombinasjoner')
- combinatorial = (10 * 9 * 10) + (10 * 9 * 9) + (10 * 9 * 10)
- print(f'Kombinatorisk løsning: {combinatorial}')
- print(f'Sannsynlighet: {combinatorial/100000}')
- print('Alle kombinasjoner:')
- for c in combinations:
- print("{:05d}".format(c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement