this would only be true if it's a single chest that can appear within the 20% prob, since it's two chests that overlap, you can't use infinite summation, so your options are quadratic formula or monte carlo simulation
wtf is this moronic and cringe gatekeeper problem?
How do you even write a program for this?
This is an easy-tier high school math problem.
You should have posted it on IQfy, it's more relevant there.
>wtf is this moronic and cringe gatekeeper problem? >How do you even write a program for this?
You're wrong and it says you can write in any language you choose.
probabilistic answer (in py3 because you seem moronic)
```
import random
data = []
def chest(data):
possible = [1,1,1,1,1,2,2,2,3,3]
c = random.choice(possible)
if c == 1:
data.append(0)
if c == 2:
data.append(1)
if c == 3:
chest(data)
for i in range(10000000):
chest(data)
result = data.count(1)/ (data.count(1) + data.count(0))
print(result)
```
>How do you even write a program for this?
monte carlo simulation
essentially, write a function that acts like the chest:
generate a random number X between 0 and 1
if X is between 0 and 0.5 return false
if X is between 0.5 and 0.8 return true
if X is between 0.8 and 1 return the function itself two times (only one of the chests needs to return true, but it can continue recursively to find at least one returning true if more chests are found)
then, call the function 100,000 times and find the proportion of true that was returned
Simulating it is cringe
Isn't there some dp solution for this?
[...]
[...]
Ok I figured it out
How about this?
#include <bits/stdc++.h>
#define MAXN 2000LL
using namespace std;
typedef long long ll;
double dp[2][MAXN];
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
dp[0][1] = 0.8;
double ans = 0;
for(ll i = 0; i < 2000; i++) {
for(ll j = 2; j < MAXN - 1; j++)
dp[1-(i&1)][j] = dp[i&1][j - 1] * 0.2 + dp[i&1][j + 1] * 0.8;
dp[1-(i&1)][1] = dp[i&1][2] * 0.8;
dp[1-(i&1)][MAXN - 1] = dp[i&1][MAXN - 2] * 0.2;
double expected = 0;
for(ll i = 1; i < MAXN; i++)
expected += dp[1-(i&1)][i] * i;
double bad = pow(0.5, expected);
ans += 1 - bad;
}
ans = 2 - ans;
cout << ans << 'n';
return 0;
}
This gets me 0.438475
Is that corect?
you're close, but the exact solution is 0.4364917, my simulation is giving me probability: 0.4364493 with one million iterations
no idea but you got the same answer as
[...] >(-0.6 + sqrt(0.6)) / 0.4 = 43.6%
would probably be closer if you ran more iterations. would be curious to know how they got that math
quadratic formula, P = 0.3 + 0.2(2P - P^2), set to 0 and find the positive root
1 month ago
Anonymous
to clarify for other anons, this formula comes from modeling it as a branching process and finding the fixed point. If P is chance of obtaining at least one gold bar, by criteria in the problem we have p = 0.3 + 0.2*(1 - (1-p)(1-p)).
1 month ago
Anonymous
yeah that works, I was thinking of the union of two events when I solved it P(AuB) = P(A) + P(B) - P(AnB), since A and B are the same event, it can be shortened to 2P - P^2
>How do you even write a program for this?
monte carlo simulation
essentially, write a function that acts like the chest:
generate a random number X between 0 and 1
if X is between 0 and 0.5 return false
if X is between 0.5 and 0.8 return true
if X is between 0.8 and 1 return the function itself two times (only one of the chests needs to return true, but it can continue recursively to find at least one returning true if more chests are found)
then, call the function 100,000 times and find the proportion of true that was returned
[...]
Simulating it is cringe
Isn't there some dp solution for this?
Ok I figured it out
How about this?
#include <bits/stdc++.h>
#define MAXN 2000LL
using namespace std;
typedef long long ll;
double dp[2][MAXN];
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
dp[0][1] = 0.8;
double ans = 0;
for(ll i = 0; i < 2000; i++) {
for(ll j = 2; j < MAXN - 1; j++)
dp[1-(i&1)][j] = dp[i&1][j - 1] * 0.2 + dp[i&1][j + 1] * 0.8;
dp[1-(i&1)][1] = dp[i&1][2] * 0.8;
dp[1-(i&1)][MAXN - 1] = dp[i&1][MAXN - 2] * 0.2;
double expected = 0;
for(ll i = 1; i < MAXN; i++)
expected += dp[1-(i&1)][i] * i;
double bad = pow(0.5, expected);
ans += 1 - bad;
}
ans = 2 - ans;
cout << ans << 'n';
return 0;
}
this would only be true if it's a single chest that can appear within the 20% prob, since it's two chests that overlap, you can't use infinite summation, so your options are quadratic formula or monte carlo simulation
>(-0.6 + sqrt(0.6)) / 0.4 = 43.6%
would probably be closer if you ran more iterations. would be curious to know how they got that math
>How do you even write a program for this?
monte carlo simulation
essentially, write a function that acts like the chest:
generate a random number X between 0 and 1
if X is between 0 and 0.5 return false
if X is between 0.5 and 0.8 return true
if X is between 0.8 and 1 return the function itself two times (only one of the chests needs to return true, but it can continue recursively to find at least one returning true if more chests are found)
then, call the function 100,000 times and find the proportion of true that was returned
Because the modern IQfy lurker does not belong on IQfy. Because they can't do basic math, and are thus reduced to coping with ineffective subpar method. Because they are dumb. Because they are dysgenic.
this would only be true if it's a single chest that can appear within the 20% prob, since it's two chests that overlap, you can't use infinite summation, so your options are quadratic formula or monte carlo simulation
Holy shit this broke ChatGPT
It turned red after recursively giving me the wrong answer
It said the answer was 0.6 something and I told it it has to be lower than 50% and it broke
It finally gave the right answer without explaining how and its talking gibberish when I asked it to explain the mistake
you can only add the two probabilities like that if they are mutually exclusive, but in this case, the two chests overlap, therefore, you have to subtract the intersection (P^2)
you can only add the two probabilities like that if they are mutually exclusive, but in this case, the two chests overlap, therefore, you have to subtract the intersection (P^2)
too add on to this, I'll say that if you take your example and add a third p, 0.3 + 0.2*(p + p + p), you get p = 0.75, which obviously can't be right, because you have a 50% chance of nothing and 75% chance of gold bar, the probabilities have to equal one, so that is a clue that the probabilities of the chests overlap and something needs to be subtracted, which in this case is their intersection
First, let's calculate the probability of NOT getting a gold bar. There are two ways this can happen:
1. The chest contains nothing (50% chance).
2. The chest contains two smaller chests, and neither of them contains a gold bar (0.2 * 0.7^2 = 0.098 chance - we multiply by 0.7 twice because each smaller chest has a 70% chance (100% - 30%) of NOT containing a gold bar).
So, the total probability of NOT getting a gold bar is 0.5 + 0.098 = 0.598.
Now, to find the probability of getting AT LEAST one gold bar, we simply subtract the probability of NOT getting one from 1 (certainty):
Probability (at least one gold bar) = 1 - Probability (no gold bar)
= 1 - 0.598
= 0.402
Therefore, there is a 40.2% chance of obtaining at least one gold bar from this treasure chest.
Who needs to write a program for a simple geometric summation problem?
n=1 gives .3
n=2...,K gives you chance of not obtaining a gold bar (.70)^2 or 49
0.2 * sum n->K (49/100) * (2/10)^n = (49/100) / (80/100) = 0.2 * .6125 = .1225
so in total .4225 or 42.25%
50% duh
sum 0 to inf 0.3*0.2^n = 0.375
(-0.6 + sqrt(0.6)) / 0.4 = 43.6%
this would only be true if it's a single chest that can appear within the 20% prob, since it's two chests that overlap, you can't use infinite summation, so your options are quadratic formula or monte carlo simulation
I misread it you're right
>what's a good pair of noise canceling headphones that won't give me a headache?
go to raves and get tinnitus for free
>noise canceling headphones that won't give me a headache
reconsider whether you actually need active noise canceling
wtf is this moronic and cringe gatekeeper problem?
How do you even write a program for this?
This is an easy-tier high school math problem.
You should have posted it on IQfy, it's more relevant there.
>wtf is this moronic and cringe gatekeeper problem?
>How do you even write a program for this?
You're wrong and it says you can write in any language you choose.
Yeah I though there's only 1 chest
probabilistic answer (in py3 because you seem moronic)
```
import random
data = []
def chest(data):
possible = [1,1,1,1,1,2,2,2,3,3]
c = random.choice(possible)
if c == 1:
data.append(0)
if c == 2:
data.append(1)
if c == 3:
chest(data)
for i in range(10000000):
chest(data)
result = data.count(1)/ (data.count(1) + data.count(0))
print(result)
```
Simulating it is cringe
Isn't there some dp solution for this?
>Simulating it is cringe
why?
you're close, but the exact solution is 0.4364917, my simulation is giving me probability: 0.4364493 with one million iterations
quadratic formula, P = 0.3 + 0.2(2P - P^2), set to 0 and find the positive root
to clarify for other anons, this formula comes from modeling it as a branching process and finding the fixed point. If P is chance of obtaining at least one gold bar, by criteria in the problem we have p = 0.3 + 0.2*(1 - (1-p)(1-p)).
yeah that works, I was thinking of the union of two events when I solved it P(AuB) = P(A) + P(B) - P(AnB), since A and B are the same event, it can be shortened to 2P - P^2
Ok I figured it out
How about this?
#include <bits/stdc++.h>
#define MAXN 2000LL
using namespace std;
typedef long long ll;
double dp[2][MAXN];
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
dp[0][1] = 0.8;
double ans = 0;
for(ll i = 0; i < 2000; i++) {
for(ll j = 2; j < MAXN - 1; j++)
dp[1-(i&1)][j] = dp[i&1][j - 1] * 0.2 + dp[i&1][j + 1] * 0.8;
dp[1-(i&1)][1] = dp[i&1][2] * 0.8;
dp[1-(i&1)][MAXN - 1] = dp[i&1][MAXN - 2] * 0.2;
double expected = 0;
for(ll i = 1; i < MAXN; i++)
expected += dp[1-(i&1)][i] * i;
double bad = pow(0.5, expected);
ans += 1 - bad;
}
ans = 2 - ans;
cout << ans << 'n';
return 0;
}
This gets me 0.438475
Is that corect?
no idea but you got the same answer as
>(-0.6 + sqrt(0.6)) / 0.4 = 43.6%
would probably be closer if you ran more iterations. would be curious to know how they got that math
In J this is just
chest =. 0:`1:`([: ($:@? +. $:@?) 100"_) @. (49 79&I.)
(+/ % #) chest"0 ? 10000000 # 100
0.436472
chest =. 0:`1:`([: +.&($:@?)~ 100"_) @. (49 79&I.)
improoved
I wasn't simulating it.
>How do you even write a program for this?
monte carlo simulation
essentially, write a function that acts like the chest:
generate a random number X between 0 and 1
if X is between 0 and 0.5 return false
if X is between 0.5 and 0.8 return true
if X is between 0.8 and 1 return the function itself two times (only one of the chests needs to return true, but it can continue recursively to find at least one returning true if more chests are found)
then, call the function 100,000 times and find the proportion of true that was returned
Because the modern IQfy lurker does not belong on IQfy. Because they can't do basic math, and are thus reduced to coping with ineffective subpar method. Because they are dumb. Because they are dysgenic.
uooooh chest erotic!
30%
Imoutos are so smart
Why would I need a program?
x=0.3+0.2*x
x=0.375
see
Sorry, didn't read.
Ok then it would be
x=0.3+0.2*(1 - (1-x)^2)
x≈0.44
cleary around 36%
const NUMBER_OF_SIMULATIONS = 100000;
function openChest() {
const random = Math.random();
if (random < 0.3) return true;
if (random < 0.5) return openChest() || openChest();
return false;
}
let gold = 0;
for (let i = 0; i < NUMBER_OF_SIMULATIONS; i++) {
if (openChest()) gold++;
}
console.log(gold / NUMBER_OF_SIMULATIONS);
>noooooooooooooo you can't apply the actual notion of probability
Holy shit this broke ChatGPT
It turned red after recursively giving me the wrong answer
It said the answer was 0.6 something and I told it it has to be lower than 50% and it broke
It finally gave the right answer without explaining how and its talking gibberish when I asked it to explain the mistake
you need to wear them for a couple of days until you get used to
bose and sennheisers have larger earcups
p=0.3 + 0.2*(p + p)
p=0.5
I know this is wrong, but why?
0.5 is just the one chest that contains nothing
so it definitely has to be smaller than 0.5 and then some
>at least one gold bar
p + p is the expected value of the number of gold bars you get after opening two chests.
you can only add the two probabilities like that if they are mutually exclusive, but in this case, the two chests overlap, therefore, you have to subtract the intersection (P^2)
too add on to this, I'll say that if you take your example and add a third p, 0.3 + 0.2*(p + p + p), you get p = 0.75, which obviously can't be right, because you have a 50% chance of nothing and 75% chance of gold bar, the probabilities have to equal one, so that is a clue that the probabilities of the chests overlap and something needs to be subtracted, which in this case is their intersection
OP's pic is too easy, here's a more fun one.
open_chest <- function() {
outcome <- sample(c("empty", "gold", "double"), 1, prob = c(0.5, 0.3, 0.2))
if (outcome == "empty") {
return(0)
} else if (outcome == "gold") {
return(1)
} else {
return(open_chest() + open_chest())
}
}
calculate_probability <- function(num_simulations, num_bars) {
count <- 0
for (i in 1:num_simulations) {
if (open_chest() == num_bars) {
count <- count + 1
}
}
probability <- count / num_simulations
return(probability)
}
num_simulations <- 100000
num_bars <- 1
probability <- calculate_probability(num_simulations, num_bars)
cat("Probability of obtaining", num_bars, "gold bar(s):", probability, "n")
What is the scuffed language? At first I thought javascript but I don't think javascript uses <- for assignment.
R
For n = 1
x = 0.3 + 0.2 *(1 - (1-x)(1-x) - x*x)
x ≈ 0.395644
No idea how to do it for bigger ns and my simulation gives me 0.387 instead.
First, let's calculate the probability of NOT getting a gold bar. There are two ways this can happen:
1. The chest contains nothing (50% chance).
2. The chest contains two smaller chests, and neither of them contains a gold bar (0.2 * 0.7^2 = 0.098 chance - we multiply by 0.7 twice because each smaller chest has a 70% chance (100% - 30%) of NOT containing a gold bar).
So, the total probability of NOT getting a gold bar is 0.5 + 0.098 = 0.598.
Now, to find the probability of getting AT LEAST one gold bar, we simply subtract the probability of NOT getting one from 1 (certainty):
Probability (at least one gold bar) = 1 - Probability (no gold bar)
= 1 - 0.598
= 0.402
Therefore, there is a 40.2% chance of obtaining at least one gold bar from this treasure chest.
I got 3/8. Someone wanna check my math?
never mind, i am a moron and can't even read the question
Been using pic related for almost a year. Very happy with them.
My hearing is pretty sensitive, so strong active noise canceling was a priority.
Who needs to write a program for a simple geometric summation problem?
n=1 gives .3
n=2...,K gives you chance of not obtaining a gold bar (.70)^2 or 49
0.2 * sum n->K (49/100) * (2/10)^n = (49/100) / (80/100) = 0.2 * .6125 = .1225
so in total .4225 or 42.25%
Wrong it's ~0.43649167
The closed form is
x=0.3+0.2*1-(1-x)^2 (right associative)
For the same reason you can't write 1..k you can't write 2..k, so yours is just a second order approximation of the answer
I hate math and exams
I'm also too dumb to solve this
50%
You either get a gold bar or you don't.
100% chance of having sexo with Kurisu
I ran 10^9 times and got 0.4364961
About tree fiddy