| Aleksey RandBits 3333 | Григорьев Денис, 124ая RandBits 2918 | ||||
|---|---|---|---|---|---|
| f | 1 | import random | f | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| n | 4 | if n < 1 or n > p or p > 18: | n | 4 | if n == 0 or n > p or p <= 0: |
| 5 | return 0 | 5 | return 0 | ||
| t | 6 | a = random.sample(range(p), n) | t | 6 | positions = random.sample(range(p), n) |
| 7 | b = 0 | 7 | x = 0 | ||
| 8 | for i in a: | 8 | for pos in positions: | ||
| 9 | b |= 1 << i | 9 | x |= 1 << pos | ||
| 10 | return b | 10 | return x | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||