2021-06-15 00:49:18 -07:00
|
|
|
---
|
|
|
|
id: 5900f4b01000cf542c50ffc2
|
2022-03-01 21:39:26 +05:30
|
|
|
title: 'Problema 323: Operazioni sui bit di interi casuali'
|
2021-06-15 00:49:18 -07:00
|
|
|
challengeType: 5
|
|
|
|
forumTopicId: 301980
|
|
|
|
dashedName: problem-323-bitwise-or-operations-on-random-integers
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
Sia $y_0, y_1, y_2, \ldots$ una sequenza di numeri interi casuali a 32 bit senza segno
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
(cioè $0 ≤ y_i < 2^{32}$, con ogni valore ugualmente probabile).
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
Per la sequenza $x_i$ viene fornita la seguente ricorsione:
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
- $x_0 = 0$ e
|
|
|
|
- $x_i = x_{i - 1} \mathbf{|} y_{i - 1}$, per $i > 0$. ($\mathbf{|}$ è l'operatore bitwise-OR)
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
Si può vedere che alla fine ci sarà un indice $N$ tale che $x_i = 2^{32} - 1$ (un bit-pattern di solo uno) per tutti $i ≥ N$.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
Trova il valore atteso di $N$. Dare la risposta arrotondata a 10 cifre dopo il punto decimale.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
`bitwiseOrOnRandomIntegers()` dovrebbe restituire `6.3551758451`.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
2022-03-01 21:39:26 +05:30
|
|
|
assert.strictEqual(bitwiseOrOnRandomIntegers(), 6.3551758451);
|
2021-06-15 00:49:18 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
2022-03-01 21:39:26 +05:30
|
|
|
function bitwiseOrOnRandomIntegers() {
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-01 21:39:26 +05:30
|
|
|
bitwiseOrOnRandomIntegers();
|
2021-06-15 00:49:18 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|