Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
The community is reviewing whether to reopen this question as of 26 days ago.
Improve this question
What does it mean to say "do this with probability p"? Does it mean that if p > 0.5, we will do "this"?
How would you write the code or algorithm for doing something with the probability p?
Thank you,
No, it's more or less: choose a random number between 0 and 1 then, if that's is less than or equal to p, do something.
For example, say p is equal to 0.75 (do something with a probability of 75%). When selecting random numbers in the range 0 through 1, about 75% of them will be 0.75 or less.
In terms of programming, you could code this up as (pseudo-code, obviously):
def do (action, probability):
if rand() <= probability:
action
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In A* algorithm, if g=0 and h=0 then what will be the result of f?
I know f(x)=g(x)+h(x). So it is true that f(x) will be zero?
f(x) would be 0.
But this should hardly ever occur.
g(x)=0 means you had no costs to reach x (should only be the case for the starting point)
h(x)=0 means the heuristics says that the costs to reach the goal from x costs not more than 0 (means that you are at the goal)
so f(x)=0 should only be possible if you start at the goal.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Number of independent trials is N, probability of success is p. I want to calculate
Probability of m consecutive successes.
Probability of m or more consecutive successes.
The numbers are very large, so the algorithm should be highly optimized.
N = 877646440
m = 79279,
p = 6204/6205 (or 0.999838839645447....)
I seem to have the answer on mathematical SE where I originally started this question. https://math.stackexchange.com/questions/1888887/easily-calculable-minimum-probability-for-m-or-more-consecutive-outcomes/1889372#1889372
I will implement that solution and update the questions.
Edit: I have gotten the answer on the mathematical SE question and implemented the solution.
Thanks
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need help with the following problem:
for i <- 5 to m do P(i)
where P(i) is executed (m-i) times provided m >= 3
I realize that this is the summation
But I'm not sure exactly how to calculate the run time from this. Any suggestions?
If you count complexity of P(i) as constant, then you have just loop m - 5 times - it will give you complexity O(m)
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I would like to count down with in a limit but in circular manner.
Let us say The limit is 12 and the current iteration is 10 then I would like to the result as 10 - 2 = 8
similar way if the current iteration is 0 the I should have result as follows 0 - 2 = 11 not -2.
The main think I would like to have this as an algorithm / formula.
Thanks.
Use modolus operator and Zn group:
(i < 0 ? n + i : i) % n
Where n is the number - 12 in your example, and i is the iteration number.
(assuming -n <= i, otherwise you might want to subtract k*n - i for some natural k to make sure the result is positive. If you do the above step iteratively, this should not be an issue.)
As a side note, in pure mathematical concept -i == n-i in the Zn group, but most programming languages I am aware of does not do this calculation, and after modolus calculation the sign of the left operand remains the same.
For this we first check the sign, and make sure it is positive.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
does gcd(gcd(a,b),gcd(c,d)) equal gcd(a,b,c,d)?or how can i calculate gcd of 4 number?
yes that is correct. If you are finding the gcd of (a,b,c,d) then any split should work. So gcd(a,b,c,d) = gcd(gcd (a,b) , gcd(c,d))
Yes. GCD(a,b,c,d) = GCD(a, GCD(b, GCD(c, d))) (or any other order, its associative and commutative.) Oh, and just in case you didn't know, you can use the Euclidean algorithm to compute GCD very quickly.