Share Your Experience: Take the 2024 Developer Survey

# Questions tagged [probability-theory]

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

70 questions
Filter by
Sorted by
Tagged with
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 ...
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 ...
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 ...
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 ...
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 ...
519 views

### Pick a random string at a fixed edit distance

I have string $s$ of length $n$ and some constant integer $k$ which is at most $n$. Give the fastest algorithm to sample a random string with Levenshtein distance $k$ from $s$ uniformly. ...
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 ...
338 views

### Probabilistic approach puzzle

A few hours earlier, I got this puzzle: Suppose, you toss a coin n times, then what is the probability of getting m number of heads? ( where m belongs to the set of all prime numbers) For instance,...
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 ...
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 ...
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 ...
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 ...
189 views

### Calculate the probability of getting this hand in n tries [closed]

Imagine there is a card game where the primary objective of the game is to get 4 of one card in your hand. Game mechanics Each player starts of with 10 cards in their hand. The remaining 32 cards (...
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 ...
2k views

### Frequency Distribution of Multiple Dice Rolls

Given two positive integers a and b, output the frequency distribution of rolling a b-sided ...
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 ...
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 ...
739 views

### Yet another coin flipping problem

Problem Starting with a set of 10 coins at the start where all coins are tails up, and given n number of integers $x_1, x_2, x_3... x_n$ representing n rounds of coin flipping. At each round, we ...
1k views

### Odds that a string of N digits contains two or more of the same

I have to fill in 2fa codes all day. They're 6-digit strings. One day I noticed that not once did any of these codes contain 6 unique digits, like 198532 There was always at least one double, like ...
201 views

### A Suitable Mission — The Professor's Revenge

Summer Klerance turned in her term assignment for this challenge. Her professor was miffed (but also amused) when he overheard a disgruntled classmate of Summer's saying she got her answers by ...
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 ...
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 ...
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 ...
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 ...
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 ...
262 views

### Estimate the mean minimum Hamming distance

Task Inputs $b \leq 100$ and $n \geq 2$. Consider $n$ binary strings, each of length $b$ sampled uniformly and independently. We would like to compute the expected minimum Hamming distance ...
2k views

358 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 ...
177 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 ...
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 ...
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). ...
526 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 ...
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 ...
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. ...
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 ...
297 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 ...