Skip to main content

Questions tagged [probability-theory]

Challenges which involve computing probabilities for random variables and stochastic processes.

Filter by
Sorted by
Tagged with
51 votes
30 answers
12k views

What an Odd Function

Your task here will be to implement a function1 that forms a permutation on the positive integers (A bijection from the positive integers onto themselves). This means that each positive integer ...
Wheat Wizard's user avatar
  • 98.8k
43 votes
10 answers
3k views

Not Your Routine Bean Machine

Consider this ASCII version of a mechanism similar to a bean machine or plinko/pachinko game: O ^ \ ^ ^ ^ \ \ ^ / ^ U U U U U 1 2 3 4 5 The ...
Calvin's Hobbies's user avatar
33 votes
49 answers
3k views

1/N probability

Because there are not enough simple code-golf challenges: Create an optionally unnamed program or function that, given (by any means) an integer 1 ≤ N ≤ 10000, outputs your language's True value with ...
Adám's user avatar
  • 30.4k
32 votes
28 answers
7k views

Choose The Powerball Numbers!

Powerball is an American lottery that has recently gained attention because the current jackpot (as of January 11, 2016) is the largest lotto prize in history, at about $1.5 billion (USD). Powerball ...
Calvin's Hobbies's user avatar
32 votes
7 answers
2k views

Are these dice nontransitive?

Nontransitive dice are nice little toys that defy our intuition in probability theory. We'll need a few definitions for this challenge: Consider two dice A and B which are thrown at the same time. We ...
Martin Ender's user avatar
30 votes
8 answers
2k views

Extreme Whitewater Canoeing

You are paddling a canoe down a fairly fast whitewater river. Suddenly, your paddles explode, and you find yourself in a dangerous situation hurtling down a river rapid without any paddles. Luckily, ...
absinthe's user avatar
  • 8,629
28 votes
36 answers
8k views

Pick a random number between 0 and n using a constant source of randomness

Task Given a positive integer n less than 2^30 specified as input in any way you choose, your code should output a random ...
user avatar
26 votes
3 answers
686 views

A lean, mean bean machine

A classic example to introduce people to the concept of a discrete probability distribution is the bean machine. This machine has a large amount of marbles fall from a narrow passageway at the top, ...
CensoredUsername's user avatar
24 votes
22 answers
2k views

Frequency Distribution of Mixed Dice Rolls

A follow-up to this challenge Given a set of mixed dice, output the frequency distribution of rolling all of them and summing the rolled numbers on each die. For example, consider ...
user avatar
23 votes
22 answers
2k views

Frequency Distribution of Multiple Dice Rolls

Given two positive integers a and b, output the frequency distribution of rolling a b-sided ...
user avatar
23 votes
24 answers
2k views

Sample the Pareto Distribution

The Pareto Distribution is a probability distribution that comes up a lot in nature. It has lots of special properties, such as an infinite mean. In this challenge, you will output a number sampled ...
isaacg's user avatar
  • 42k
21 votes
15 answers
1k views

Penney-Conway odds

Background Penney's game is a two-player game about coin tossing. Player A announces a sequence of heads and tails of length \$n\$, then player B selects a different sequence of same length. The ...
Bubbler's user avatar
  • 77.1k
21 votes
21 answers
2k views

Sample integers that sum to one hundred

Given a positive integer n, randomly output n non negative integers that sum to one hundred. n will be at most 200. The output should be present as a list of integers (not sorted). Your random sample ...
user avatar
21 votes
4 answers
2k views

Avoiding Loops!

Given a collection of coloured laces, what would be the probability, \$P\$, that Alice won't create any loops if, until impossible, they tie two uniformly chosen, free lace ends of differing colours ...
Jonathan Allan's user avatar
21 votes
2 answers
976 views

Prepare to... die?

Background One source of ennui in tabletop role-playing games is dealing with rolls involving many dice. Casting a Disintegration spell may be instantaneous, but rolling and adding together 40 dice ...
Uri Granta's user avatar
  • 2,959
20 votes
9 answers
835 views

Hand patterns in a card game

A deck of cards is the Cartesian product of S suits and R ranks. Many, though not all, card games use ...
ngn's user avatar
  • 15.3k
20 votes
7 answers
2k views

Sample a random non-decreasing sequence

Input: Two integers n and k given in any form that is convenient for your code Output A random non-decreasing sequence of k integers, each in the range 1 to n. The sample should be chosen uniformly ...
user avatar
20 votes
5 answers
1k views

Fix a broken random function

A friend has an add-on card in their computer which generates a perfectly random number from 1 to 5 inclusive. Unfortunately, they spilt cola on it somehow, and it now generates only 2's for all ...
Thomas O's user avatar
  • 3,348
20 votes
8 answers
1k views

Pick-flatten a list

Consider the process of "picking" a nested list. Picking is defined as follows: If the argument is a list, take an element from the list at random (uniformly), and pick from that. If the argument is ...
Esolanging Fruit's user avatar
20 votes
4 answers
1k views

(Somewhat) Pedantic Birthday Paradox

Background The birthday paradox is a popular problem in probability theory which defies (most people's) mathematical intuition. The problem statement is: Given N people, what is the probability ...
Martin Ender's user avatar
18 votes
14 answers
2k views

Lucky dice rolls

Lucky dice rolls In pen and paper roleplaying games dice are used for various chance calculations. The usual way to describe a roll is \$n\textbf{d}k\$ where \$n\$ is the number of dice and \$k\$ is ...
Gábor Fekete's user avatar
18 votes
16 answers
1k views

Probability of All Combinations of Given Events

Given a sequences of events with probabilities between 0.0 and 1.0, generate and derive the probability of each combination occurring. You may presume that a sequence of numbers is provided in ...
Mark Johnson's user avatar
18 votes
20 answers
1k views

Compute the histogram entropy estimation of a string

Write a program or function that estimates the Shannon entropy of a given string. If a string has n characters, d distinct characters, xi is the i th distinct character, and P(xi) is the probability ...
orlp's user avatar
  • 39.1k
16 votes
13 answers
2k views

Probabilistically fair prize splitting for two-player coin toss

Introduction Adam (A) and Bubbler (B) are playing coin toss, where the one who wins 5 times first would win the prize of $32. If the game is aborted when the scores are ...
Bubbler's user avatar
  • 77.1k
16 votes
25 answers
2k views

Sums of 100 Rolls of Two Six Sided Dice

Suppose you have two six-sided dice. Roll the pair 100 times, calculating the sum of each pair. Print out the number of times each sum occurred. If a sum was never rolled, you must include a zero or ...
Caidan's user avatar
  • 161
16 votes
6 answers
587 views

Who's that probability distribution?

Introduction In this challenge, you are given a list of nonnegative floating point numbers drawn independently from some probability distribution. Your task is to infer that distribution from the ...
Zgarb's user avatar
  • 42.7k
15 votes
3 answers
807 views

Build a program to analyze coin flip sequence choices

In a puzzle in an old book of mine, a game is defined in which two players choose sequences of coin flips that they believe will appear first when a coin is repeatedly flipped. (It was actually odd ...
Joe Z.'s user avatar
  • 35k
14 votes
15 answers
1k views

Weighted coin flip strings

Given n, k, and p, find the probability that a weighted coin with probability p of heads will flip heads at least k times in a row in n flips, correct to 3 decimal digits after decimal point (changed ...
dancxviii's user avatar
  • 193
13 votes
12 answers
2k views

Odds for second smallest prime factor

Given a prime number \$p\$ output the asymptotic density of the set of positive integers which have \$p\$ as their second-smallest distinct prime factor Input/Output Input: one of the following ...
Mukundan314's user avatar
  • 12.3k
13 votes
11 answers
2k views

Calculate the probability of getting to the target first (exactly)

Consider the following probability puzzle. We start with a string of bits all set to 0. At each step we choose a bit uniformly and independently at random and flip it. The value your code has to ...
user avatar
13 votes
7 answers
1k views

Compute probability of seeing all the balls

Given \$x\$ distinguishable balls (say they have different colors), sample with replacement repeatedly until all the balls that have been seen, have been seen at least twice. Challenge The input is ...
Simd's user avatar
  • 3,114
13 votes
3 answers
2k views

Computer: you do the math

This challenge is partly an algorithms challenge, involves some math and is partly simply a fastest code challenge. For some positive integer n, consider a ...
user avatar
13 votes
2 answers
400 views

Pólya urn flip and roll

Problem statement Pólya is playing about with his urn again and he wants you to help him calculate some probabilities. In this urn experiment Pólya has an urn which initially contains 1 red and 1 blue ...
Expired Data's user avatar
  • 4,001
13 votes
1 answer
1k views

XKCD Bracket Probabilities

Today's XKCD is a sports-tournament style bracket, where the contestants are well-known names, put into groups of possibly confusing names. Give the probability that a given contestant will win the ...
Digital Trauma's user avatar
12 votes
5 answers
5k views

Plot the Gaussian Distribution in 3D

In probability theory, the normal (or Gaussian) distribution is a very common continuous probability distribution. Normal distributions are important in statistics and are often used in the natural ...
MD XF's user avatar
  • 13.9k
12 votes
4 answers
625 views

Code golf a random orthogonal matrix

An orthogonal matrix is a square matrix with real entries whose columns and rows are orthogonal unit vectors (i.e., orthonormal vectors). This means that M^T M = I, where I is the identity matrix ...
user avatar
12 votes
4 answers
868 views

Uncertainty in the Timeline of a Day

Suppose your alarm wakes you up one morning, but you hit snooze so you can sleep for 8 more minutes. When it rings again you grudgingly get up and take a shower, which you estimate takes 15 to 17 ...
Calvin's Hobbies's user avatar
12 votes
3 answers
527 views

Generalized Birthday Problem

Tonight, my fiancée took me out to dinner to celebrate my birthday. While we were out, I heard Happy Birthday sung to 5 different guests (including myself), in a restaurant full of 50 people. This got ...
user avatar
11 votes
3 answers
444 views

What's the chance that I'll win a door prize?

My local ACM chapter gives out door prizes to people who come to the meetings. You get an increased chance of winning if you solve the programming puzzle, however (but I always solve that puzzle). ...
Justin's user avatar
  • 21.2k
10 votes
5 answers
1k views

Calculate a probability exactly and quickly

[This is a partner question to Calculate a probability exactly ] This task is about writing code to compute a probability exactly and quickly. The output should be a precise probability written as a ...
user avatar
10 votes
15 answers
1k views

Probability of something happening at least n out of m times

Write a program or function, that given a success probability p, a number n and a number of trials m returns the chance of at least n successes out of m trials. Your answer must be precise to at ...
orlp's user avatar
  • 39.1k
10 votes
20 answers
975 views

Calculate probability of getting half as many heads as coin tosses.

Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads. For example, given 2 coins ...
david4dev's user avatar
  • 693
10 votes
2 answers
939 views

Probabilities - how high can you go?

I previously asked a question for how to compute a probability quickly and accurately. However, evidently it was too easy as a closed form solution was given! Here is a more difficult version. This ...
user avatar
9 votes
11 answers
2k views

"i" have "i" chance of occuring

Design a random number generator where the i th number has i% chance of occurring for all 0 < i < 14. 0 should have exactly 9% chance of occurring. The seed for the generator should be the ...
ghosts_in_the_code's user avatar
9 votes
4 answers
1k views

Calculate a probability exactly

This task is about writing code to compute a probability exactly. The output should be a precise probability written as a fraction in its most reduced form. That is it should never output ...
user avatar
9 votes
5 answers
2k views

Random factorized numbers

Input The code should take an integer \$n\$ between 1 and 1000. Output The code should output positive integers with \$n\$ bits. Accompanying each integer should be its full factorization. Each ...
Simd's user avatar
  • 3,114
9 votes
1 answer
349 views

Knockout probabilities

Knockout is a basketball game where players take turns shooting. It is played as a sequence of two-player contests, each of which has the possibility of "knocking out" one of those players. Suppose ...
soktinpk's user avatar
  • 4,452
9 votes
2 answers
206 views

Talent rolls in DSA

Some friends and I have played some DSA (a mainly german tabletop RPG much like D&D). I was wondering what the chance on passing rolls are, so you will have to write some code to calculate it. ...
Eumel's user avatar
  • 2,625
8 votes
7 answers
468 views

A Suitable Mission

Summer Klerance, a senior in college, is what her teachers refer to as GBL*. Students in her probability class have been assigned individual problems to work on and turn in as part of their final ...
DjinTonic's user avatar
  • 636
8 votes
6 answers
301 views

Card pair probability

Given a deck consisting of N copies of cards with integer values [1,M] for a total of N*M cards, compute the probability that a card with the value of 1 is adjacent to a card with the value of 2. ...
helloworld922's user avatar