Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Round trip stones

$N$ vessels initially contain $3$ stones each. What is the probability of having at least $3$ stones in the first vessel after moving a uniformly random selection from the first vessel to the secon...

1 answer  ·  posted 7mo ago by trichoplax‭  ·  last activity 7mo ago by Arpad Horvath‭

#2: Post edited by user avatar trichoplax‭ · 2024-05-02T07:51:40Z (7 months ago)
Fix inconsistent number formating
  • $N$ vessels initially contain $3$ stones each. What is the probability of having at least $3$ stones in the first vessel after moving a uniformly random selection from the first vessel to the second, then from the second vessel to the third, and so on back to the first vessel?
  • ## Input
  • - A positive integer $N$.
  • - Your code must work for inputs up to and including $10$, but may crash, error, or give incorrect output for larger inputs.
  • ## Output
  • - A probability $p$, so $0 \le p \le 1$.
  • - Your output is valid if rounding it to $6$ decimal places results in the output shown in the relevant test case.
  • - This is the probability of the first vessel containing greater than or equal to $3$ stones after the following process:
  • - Start with $N$ vessels containing $3$ stones each.
  • - For each vessel from $1$ to $N$ in order:
  • - Choose uniformly randomly between $0$ and all of the stones from the vessel, and move them to the next vessel.
  • - Note that when moving from vessel $N$, they are moved back to vessel $1$.
  • ## Examples
  • ### Input 1
  • When there is only $1$ vessel, all of the stones moved from it are moved back into it, resulting in exactly $3$ stones in vessel $1$, so the probability of there being at least $3$ stones in vessel $1$ is $1$.
  • ### Input 2
  • When there are $2$ vessels, the process goes like this:
  • - $0$, $1$, $2$, or $3$ stones are taken from vessel $1$ and added to vessel $2$. For example, $2$ stones may be taken from vessel $1$ and added to vessel $2$.
  • - There are now $5$ stones in vessel $2$, so $0$, $1$, $2$, $3$, $4$, or $5$ stones are taken from vessel $2$ and moved back to vessel $1$.
  • There are $22$ ways that this process can happen, and $16$ of those ways result in $3$ or more stones in vessel $1$. This means that the probability of there being at least $3$ stones in vessel $1$ is $16/22=0.727273$ (rounded to $6$ decimal places).
  • ### Input 3
  • When there are $3$ vessels, the process goes like this:
  • - $0$, $1$, $2$, or $3$ stones are taken from vessel $1$ and added to vessel $2$. For example, $2$ stones may be taken from vessel $1$ and added to vessel $2$.
  • - There are now $5$ stones in vessel $2$, so $0$, $1$, $2$, $3$, $4$, or $5$ stones are taken from vessel $2$ and added to vessel $3$. For example, $5$ stones may be taken from vessel $2$ and added to vessel $3$.
  • - There are now $8$ stones in vessel $3$, so $0$, $1$, $2$, $3$, $4$, $5$, $6$, $7$, or $8$ stones are taken from vessel $3$ and moved back to vessel $1$.
  • There are $140$ ways that this process can happen, and $102$ of those ways result in $3$ or more stones in vessel $1$. The probability of there being at least $3$ stones in vessel $1$ is $102/140=0.728571$ (rounded to $6$ decimal places).
  • ## Test cases
  • Test cases are in the format `input : output`, and are rounded to 6 decimal places. For example, an output of `0.727272727` is equivalent to an output of `0.727273` when rounded.
  • ```text
  • 1 : 1.000000
  • 2 : 0.727273
  • 3 : 0.728571
  • 4 : 0.736842
  • 5 : 0.743789
  • 6 : 0.749164
  • 7 : 0.753344
  • 8 : 0.756657
  • 9 : 0.759336
  • 10 : 0.761542
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • $N$ vessels initially contain $3$ stones each. What is the probability of having at least $3$ stones in the first vessel after moving a uniformly random selection from the first vessel to the second, then from the second vessel to the third, and so on back to the first vessel?
  • ## Input
  • - A positive integer $N$.
  • - Your code must work for inputs up to and including $10$, but may crash, error, or give incorrect output for larger inputs.
  • ## Output
  • - A probability $p$, so $0 \le p \le 1$.
  • - Your output is valid if rounding it to $6$ decimal places results in the output shown in the relevant test case.
  • - This is the probability of the first vessel containing greater than or equal to $3$ stones after the following process:
  • - Start with $N$ vessels containing $3$ stones each.
  • - For each vessel from $1$ to $N$ in order:
  • - Choose uniformly randomly between $0$ and all of the stones from the vessel, and move them to the next vessel.
  • - Note that when moving from vessel $N$, they are moved back to vessel $1$.
  • ## Examples
  • ### Input 1
  • When there is only $1$ vessel, all of the stones moved from it are moved back into it, resulting in exactly $3$ stones in vessel $1$, so the probability of there being at least $3$ stones in vessel $1$ is $1$.
  • ### Input 2
  • When there are $2$ vessels, the process goes like this:
  • - $0$, $1$, $2$, or $3$ stones are taken from vessel $1$ and added to vessel $2$. For example, $2$ stones may be taken from vessel $1$ and added to vessel $2$.
  • - There are now $5$ stones in vessel $2$, so $0$, $1$, $2$, $3$, $4$, or $5$ stones are taken from vessel $2$ and moved back to vessel $1$.
  • There are $22$ ways that this process can happen, and $16$ of those ways result in $3$ or more stones in vessel $1$. This means that the probability of there being at least $3$ stones in vessel $1$ is $16/22=0.727273$ (rounded to $6$ decimal places).
  • ### Input 3
  • When there are $3$ vessels, the process goes like this:
  • - $0$, $1$, $2$, or $3$ stones are taken from vessel $1$ and added to vessel $2$. For example, $2$ stones may be taken from vessel $1$ and added to vessel $2$.
  • - There are now $5$ stones in vessel $2$, so $0$, $1$, $2$, $3$, $4$, or $5$ stones are taken from vessel $2$ and added to vessel $3$. For example, $5$ stones may be taken from vessel $2$ and added to vessel $3$.
  • - There are now $8$ stones in vessel $3$, so $0$, $1$, $2$, $3$, $4$, $5$, $6$, $7$, or $8$ stones are taken from vessel $3$ and moved back to vessel $1$.
  • There are $140$ ways that this process can happen, and $102$ of those ways result in $3$ or more stones in vessel $1$. The probability of there being at least $3$ stones in vessel $1$ is $102/140=0.728571$ (rounded to $6$ decimal places).
  • ## Test cases
  • Test cases are in the format `input : output`, and are rounded to $6$ decimal places. For example, an output of `0.727272727` is equivalent to an output of `0.727273` when rounded.
  • ```text
  • 1 : 1.000000
  • 2 : 0.727273
  • 3 : 0.728571
  • 4 : 0.736842
  • 5 : 0.743789
  • 6 : 0.749164
  • 7 : 0.753344
  • 8 : 0.756657
  • 9 : 0.759336
  • 10 : 0.761542
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#1: Initial revision by user avatar trichoplax‭ · 2024-04-12T10:41:42Z (7 months ago)
Round trip stones
$N$ vessels initially contain $3$ stones each. What is the probability of having at least $3$ stones in the first vessel after moving a uniformly random selection from the first vessel to the second, then from the second vessel to the third, and so on back to the first vessel?

## Input
- A positive integer $N$.
- Your code must work for inputs up to and including $10$, but may crash, error, or give incorrect output for larger inputs.

## Output
- A probability $p$, so $0 \le p \le 1$.
- Your output is valid if rounding it to $6$ decimal places results in the output shown in the relevant test case.
- This is the probability of the first vessel containing greater than or equal to $3$ stones after the following process:
  - Start with $N$ vessels containing $3$ stones each.
  - For each vessel from $1$ to $N$ in order:
    - Choose uniformly randomly between $0$ and all of the stones from the vessel, and move them to the next vessel.
    - Note that when moving from vessel $N$, they are moved back to vessel $1$.

## Examples

### Input 1
When there is only $1$ vessel, all of the stones moved from it are moved back into it, resulting in exactly $3$ stones in vessel $1$, so the probability of there being at least $3$ stones in vessel $1$ is $1$.

### Input 2
When there are $2$ vessels, the process goes like this:
- $0$, $1$, $2$, or $3$ stones are taken from vessel $1$ and added to vessel $2$. For example, $2$ stones may be taken from vessel $1$ and added to vessel $2$.
- There are now $5$ stones in vessel $2$, so $0$, $1$, $2$, $3$, $4$, or $5$ stones are taken from vessel $2$ and moved back to vessel $1$.

There are $22$ ways that this process can happen, and $16$ of those ways result in $3$ or more stones in vessel $1$. This means that the probability of there being at least $3$ stones in vessel $1$ is $16/22=0.727273$ (rounded to $6$ decimal places).

### Input 3
When there are $3$ vessels, the process goes like this:
- $0$, $1$, $2$, or $3$ stones are taken from vessel $1$ and added to vessel $2$. For example, $2$ stones may be taken from vessel $1$ and added to vessel $2$.
- There are now $5$ stones in vessel $2$, so $0$, $1$, $2$, $3$, $4$, or $5$ stones are taken from vessel $2$ and added to vessel $3$. For example, $5$ stones may be taken from vessel $2$ and added to vessel $3$.
- There are now $8$ stones in vessel $3$, so $0$, $1$, $2$, $3$, $4$, $5$, $6$, $7$, or $8$ stones are taken from vessel $3$ and moved back to vessel $1$.

There are $140$ ways that this process can happen, and $102$ of those ways result in $3$ or more stones in vessel $1$. The probability of there being at least $3$ stones in vessel $1$ is $102/140=0.728571$ (rounded to $6$ decimal places).

## Test cases
Test cases are in the format `input : output`, and are rounded to 6 decimal places. For example, an output of `0.727272727` is equivalent to an output of `0.727273` when rounded.

```text
1 : 1.000000
2 : 0.727273
3 : 0.728571
4 : 0.736842
5 : 0.743789
6 : 0.749164
7 : 0.753344
8 : 0.756657
9 : 0.759336
10 : 0.761542
```

## Scoring
This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.

> Explanations are optional, but I'm more likely to upvote answers that have one.


[code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"