Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [probability-theory]

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

3
votes
7answers
254 views

Choose the Most Dramatic Outcome

The premise of this is simple: A 10% chance is pretty unlikely, but everyone knows that a one-in-a-million chance is a sure thing! So, write code that implements the following "dramatic" probability ...
6
votes
5answers
391 views

Watch the bookie win

When you roll a die, you have a 6:1 chance of any given option. There's a bookmaker taking bets on die rolls. He owns £20 at the start of the game. The bookmaker offers odds of 4:1, but gamblers ...
22
votes
24answers
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 ...
23
votes
22answers
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 ...
19
votes
9answers
739 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 ...
20
votes
8answers
872 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 ...
23
votes
22answers
2k views

Frequency Distribution of Multiple Dice Rolls

Given two positive integers a and b, output the frequency distribution of rolling a b-sided ...
26
votes
3answers
578 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, ...
8
votes
3answers
314 views

Golfception arrives

Lets play golf while we golf. Problem: Distance to the hole initially is 700m Each hit to the ball will make it advance to the hole 250-350m, this should be random. Each hit has a 5% probabilities ...
3
votes
9answers
300 views

The most unreliable gun ever [duplicate]

You are given a very special gun with a full magazine. Let n be the initial number of bullets in the magazine and i the number ...
10
votes
5answers
2k 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 ...
14
votes
23answers
988 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 ...
2
votes
2answers
167 views

Random subset generator [closed]

Randomly choose one out of k-length, ordered subset of characters in a string, while only storing a limited number of characters. The subset must be chosen with ...
26
votes
32answers
6k 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 ...
19
votes
6answers
973 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 ...
10
votes
3answers
424 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 ...
19
votes
16answers
918 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 ...
12
votes
3answers
445 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 ...
12
votes
3answers
388 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). ...
11
votes
15answers
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 ...
19
votes
20answers
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 ...
7
votes
1answer
277 views

Model a probability table using 15-bit fixed probabilities

A histogram is an array of integers that counts the number of times a symbol occurs. For example, for the string "aaabbbabbdebabbbebebdbaaabbabaaaaeebeaabaaba" a ...
34
votes
28answers
6k 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 ...
9
votes
2answers
156 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. ...
9
votes
6answers
262 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. ...
28
votes
46answers
2k 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 ...
7
votes
3answers
312 views

Guess the hidden communities

Background This challenge is about the stochastic block model. Basically, you are given an undirected graph, where the nodes represent people, and the edges represent social connections between them. ...
16
votes
6answers
515 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 ...
10
votes
11answers
1k 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 ...
9
votes
6answers
293 views

Implement an API for probability distributions

Introduction In this challenge, your task is to implement a collection of simple functions that together form a usable mini-library for simple probability distributions. To accommodate some of the ...
7
votes
2answers
271 views

Probability to clear the board or win

In the game Hearthstone there is a playing board containing friendly and enemy minions, and two heroes - yours and the enemy's. To generalize and simplify, we will assume it's your turn, the opponent ...
7
votes
2answers
299 views

Simple single-player board game, expected score distribution

This is the first problem I've posted here; please post criticisms in comments. Summary A game board consists of a starting space, an ending space, and between them are ...
9
votes
1answer
309 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 ...
10
votes
2answers
806 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 ...
10
votes
5answers
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 ...
9
votes
4answers
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 ...
13
votes
1answer
822 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 ...
42
votes
10answers
2k 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 ...
20
votes
4answers
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 ...
20
votes
2answers
907 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 ...
31
votes
7answers
1k 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 ...
15
votes
3answers
698 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 ...
13
votes
3answers
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 ...
7
votes
1answer
460 views

Evaluate CDF of Student-t distribution

The goal of this codegolf is evaluating the cumulative distribution function of the student-t probability distribution. This is not trivial since there is no closed form and the function is dependent ...
12
votes
4answers
829 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 ...
28
votes
8answers
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, ...
6
votes
5answers
934 views
6
votes
1answer
1k views

Probability to win a hand of poker (Texas hold 'em)

Challenge: In the last stage of a two players Texas hold 'em, given a two-card hand and five cards on table, determine your probability to win versus an opponent by the standard ranking of poker ...
10
votes
20answers
836 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 ...
18
votes
5answers
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 ...