2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 5900f4b01000cf542c50ffc2
|
|
|
|
title: 'Problem 323: Bitwise-OR operations on random integers'
|
2020-11-27 19:02:05 +01:00
|
|
|
challengeType: 5
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 301980
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: problem-323-bitwise-or-operations-on-random-integers
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
|
|
|
|
2022-03-19 00:56:57 -07:00
|
|
|
Let $y_0, y_1, y_2, \ldots$ be a sequence of random unsigned 32 bit integers (i.e. $0 ≤ y_i < 2^{32}$, every value equally likely).
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2021-07-29 20:59:06 +02:00
|
|
|
For the sequence $x_i$ the following recursion is given:
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-29 20:59:06 +02:00
|
|
|
- $x_0 = 0$ and
|
|
|
|
- $x_i = x_{i - 1} \mathbf{|} y_{i - 1}$, for $i > 0$. ($\mathbf{|}$ is the bitwise-OR operator)
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-29 20:59:06 +02:00
|
|
|
It can be seen that eventually there will be an index $N$ such that $x_i = 2^{32} - 1$ (a bit-pattern of all ones) for all $i ≥ N$.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-29 20:59:06 +02:00
|
|
|
Find the expected value of $N$. Give your answer rounded to 10 digits after the decimal point.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --hints--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-29 20:59:06 +02:00
|
|
|
`bitwiseOrOnRandomIntegers()` should return `6.3551758451`.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
2021-07-29 20:59:06 +02:00
|
|
|
assert.strictEqual(bitwiseOrOnRandomIntegers(), 6.3551758451);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --seed--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --seed-contents--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
2021-07-29 20:59:06 +02:00
|
|
|
function bitwiseOrOnRandomIntegers() {
|
2020-09-15 09:57:40 -07:00
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-29 20:59:06 +02:00
|
|
|
bitwiseOrOnRandomIntegers();
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|