| Nikita_luk RandBits 3390 | Владислав Коноплицкий RandBits 11210 | ||||
|---|---|---|---|---|---|
| f | 1 | import random | f | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| 4 | if n > p or n < 1: | 4 | if n > p or n < 1: | ||
| 5 | return 0 | 5 | return 0 | ||
| 6 | positions = random.sample(range(p), n) | 6 | positions = random.sample(range(p), n) | ||
| t | 7 | result = sum((1 << pos for pos in positions)) | t | 7 | result = sum((2 ** pos for pos in positions)) |
| 8 | return result | 8 | return result | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||