| Тимофей Сухорученков, 418 группа RandBits 2739 | Nikita_luk RandBits 3390 | ||||
|---|---|---|---|---|---|
| f | 1 | import random | f | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| n | 4 | if n > p or n == 0: | n | 4 | if n > p or n < 1: |
| 5 | return 0 | 5 | return 0 | ||
| t | 6 | ones_positions = random.sample(range(p), n) | t | 6 | positions = random.sample(range(p), n) |
| 7 | num = sum((1 << pos for pos in ones_positions)) | 7 | result = sum((1 << pos for pos in positions)) | ||
| 8 | return num | 8 | return result | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||