Questions tagged [combinatorics]
For challenges involving combinatorics.
392 questions
9
votes
2
answers
343
views
Putting the pieces together
In this code-golf challenge, you will count the number of ways of putting together pieces of a building toy which consists of slotted squares that interlock with one another, shown below. In ...
9
votes
1
answer
381
views
Ruler-and-compass constructions
In this code-golf challenge, you will work with a construction that was used by the ancient Greeks: the straightedge-and-compass construction. In particular, you will count how many different ...
4
votes
1
answer
288
views
Find the factor to use for shortest simple Brainfuck data initialization loop
I like writing answers using Brainfuck, since this language basically simulates a Turing machine, and it is pretty challenging to find the shortest answer for any problem, since there are a lot of ...
16
votes
17
answers
1k
views
Counting Gessel walks
OEIS A135404 gives the number of Gessel walks \$g(n)\$ of length \$2n\$. A Gessel walk is
a walk on the square lattice starting and ending at the origin
with possible steps (1,0), (-1,0), (1,1), (-1,-...
12
votes
7
answers
2k
views
Do Not Find the Fox in all possible ways
Do Not Find the Fox is a non-game where you repeat the following up to 16 times:
Pick an empty square in a 4×4 grid
Draw a tile from a bag – there are 5 Fs, 6 Os and 5 Xs at first – and place it in ...
7
votes
9
answers
1k
views
Card-Jitsu Part 1: Find all winning sets of three cards
Part 2 is available here
Card-Jitsu was a mini card-game based on Rock, Paper, Scissors available on the children MMO game Club Penguin. I first wrote a challenge where you needed to implement a clone ...
16
votes
12
answers
993
views
Repetition-restricted strings
Given an alphabet size, \$n>0\$, and an occurrence limit, \$k>0\$, produce the number, \$a(n, k)\$, of strings that may be constructed from the \$n\$ letters in the alphabet which have no more ...
15
votes
9
answers
1k
views
How many chains?
Given a positive integer \$n\$, a partition of \$n\$ is an ascending sequence of numbers that sum to \$n\$.
Given two partitions \$a\$ and \$b\$, \$a\$ is a refinement of \$b\$ iff \$b\$ can be ...
13
votes
13
answers
2k
views
Meandering over ℤ
The easiest way to understand this task is to look at this
graph,
which you can change interactively.
It defines a sequence n -> a(n) like this:
a(0) = 0; thereafter a(n) is the least integer (in ...
14
votes
11
answers
1k
views
Counting Rota-Baxter words
A Rota-Baxter word, \$w\$, is a string made of the symbols a, (, and ) such that the ...
8
votes
6
answers
1k
views
Ranking of binary trees
Let N = [0,1,2,...n-1] be the initial segment of the natural
numbers of length n, then all permutations of N can be sorted
lexicographically, starting with the identity. The index into this
sorted ...
2
votes
11
answers
824
views
Climbing through the mountains on all paths
Narrative
We are standing at the foot of a mountain. To find the best route when climbing the mountain, let's consider all possible routes.
On our route, there is no point lower than our starting ...
11
votes
6
answers
1k
views
Tracing light through a house of mirrors
Suppose you find yourself in a house of mirrors! You stand in the corner, and you trace how your image reflects off of mirror A, followed by mirror B, followed by mirror C, followed by mirror A.
But ...
15
votes
10
answers
2k
views
Walks in Nice (Nizza)
Narrative
Recently, I visited Nice (a French city on the Mediterranean coast) and saw a curious tourist wandering through the city. His walk started at the center of the 'Promenade des Anglais'. He ...
12
votes
6
answers
2k
views
Frogs on lily pads want to make a party
Consider binary strings (reading from left to right) starting with a '1' as ponds of lily pads. A '1' signifies a frog sitting on the lily pad, and a '0' represents an empty lily pad.
Here, we see a ...
7
votes
6
answers
408
views
Walks on a circle
A walk on a circle is a sequence of oriented arcs of equal length on a circle starting and ending at the same point. The endpoint of an arc is always the starting point of the next arc of the walk. ...
12
votes
10
answers
2k
views
Girls and boys parades
Donald Knuth describes the setup:
"There are \$n\$ girls \${g_1, ..., g_n}\$ and \$k\$ boys \${b_1, ..., b_k}\$,
where \$g_i\$ is younger than \$g_{i+1}\$ and \$b_j\$ is younger than
\$b_{j+1}\$, ...
7
votes
2
answers
556
views
Count the possible folds of an n² grid
Update: 8x8 case from @gsitcia has finished! according to that code, there are 162,403,827,553,180,928 ways it could be folded. now to get it into the oeis...
Inspired by this recent video, I figured ...
7
votes
12
answers
816
views
Counting constrained permutations
Challenge:
Write a program or function that, given positive integers n, t, b, c, counts permutations of 1..n where:
Exactly t numbers are in their original position
Exactly b numbers are higher than ...
13
votes
9
answers
2k
views
How many ways can you make change?
The "third type of Euler Transform" takes an integer sequence that gives the number of objects of a given weight and outputs a sequences that gives the number of multisets of objects that ...
18
votes
5
answers
1k
views
Ways to paint a backbone on a tree
Say I have some unlabelled tree graph:
I'll define a "backbone" as a path on a graph that can't be extended - both its ends are at terminal vertices. There are three ways to overlay a ...
5
votes
1
answer
376
views
Dishonest dungeon staff
This is a joint post with https://puzzling.stackexchange.com/questions/126255/dishonest-dungeon-staff
You are faced with the difficult task to set up a dungeon for adventurers. However you made a deal ...
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 ...
14
votes
13
answers
1k
views
Counting rankings
There is a competition with \$n\$ participants in total. Alice is one of the participants. The outcome of the competition is given as a ranking per participant with a possibility of ties; e.g. there ...
10
votes
6
answers
737
views
Robinson Schensted correspondence
[The explanations of the algorithm come from here. I recommend reading it for a beautiful description of the algorithm.]
This challenge is to implement the Robinson Schensted correspondence.
Input
A ...
14
votes
10
answers
1k
views
Expected number of rounds for this labeling scheme
Task
Here is an interesting math problem:
Let's say that there are \$n\$ indistinguishable unlabeled objects in a bin. For every "round", pull \$k\$ objects randomly out of the bin with ...
10
votes
7
answers
685
views
List all words following a pattern
This challenge is to list out all possible words which are built from a pattern of syllables. Words are composed by joining syllables together. Syllables are composed of a number of vowels with some ...
19
votes
14
answers
3k
views
Rook Polynomials
In combinatorics, the rook polynomial \$R_{m,n}(x)\$ of a \$m \times n\$ chessboard is the generating function for the numbers of arrangements of non-attacking rooks. To be precise:
$$R_{m,n}(x) = \...
5
votes
3
answers
529
views
Valid python function invocation signatures
Background
In Python, function arguments are defined within the parentheses following the function name in the function definition. There are different ways to present function arguments, and they can ...
10
votes
3
answers
398
views
Representing a number as an unordered list of smaller numbers
Suppose we want to encode a large integer \$x\$ as a list of words in such a way that the decoder can recover \$x\$ regardless of the order in which the words are received. Using lists of length \$k\$ ...
0
votes
1
answer
435
views
Generate all possible equations from a list of numbers [closed]
This is my first codegolf post so let me know if I have missed anything. Thanks :)
Description
You are given a list of numbers with 2 < n <= 6 length i.e. [1, ...
13
votes
15
answers
2k
views
The number of solutions to Hertzsprung's Problem
Hertzprung's Problem (OEIS A002464) is the number of solutions to a variant of the Eight Queens Puzzle, where instead of placing \$n\$ queens, you place \$n\$ rook-king fairy pieces (can attack like ...
13
votes
11
answers
2k
views
String Concatenate
You are given a string \$s\$ of characters from a to z. Your task is to count how many unique strings of length \$n\$ you can make by concatenating multiple prefixes of the string \$s\$ together.
...
16
votes
8
answers
2k
views
We're gonna need a bigger podium!
If \$R\$ runners were to run a race, in how many orders could they finish such that exactly \$T\$ runners tie?
Challenge
Given a positive integer \$R\$ and a non-negative integer \$0\leq T\leq {R}\$ ...
13
votes
17
answers
1k
views
A Fine sequence with fine interpretations
The ubiquitous Catalan numbers \$C_n\$ count the number of Dyck paths, sequences of up-steps and down-steps of length \$2n\$ that start and end on a horizontal line and never go below said line. Many ...
10
votes
6
answers
821
views
CGAC2022 Day 13: Santa's gift and the laser lock, Part 2
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
You successfully route the laser into the sensor, but nothing happens.
"What?" Frustrated, you flip the ...
20
votes
10
answers
1k
views
Counting Stripey Bracelets
A bracelet consists of a number, \$\mathit{N}\$, of beads connected in a loop. Each bead may be any of \$\mathit{C}\$ colours. Bracelets are invariant under rotation (shifting beads around the loop) ...
20
votes
8
answers
5k
views
The smallest area of a convex grid polygon
I got an email from Hugo Pfoertner, an Editor-in-Chief at the On-Line Encyclopedia of Integer Sequences, with a terrific idea for a fastest-code challenge, which will also help verify or expand the ...
15
votes
14
answers
2k
views
Find a word in the dictionary of all possible words
Given an alphabet represented as a nonempty set of positive integers, and a word made up of symbols from that alphabet, find that word's position in the lexicographically ordered set of all words, ...
15
votes
10
answers
1k
views
Count Futoshiki row solutions
Futoshiki is a logic puzzle where an \$n×n\$ Latin square must be completed based on given numbers and inequalities between adjacent cells. Each row and column must contain exactly one of each number ...
5
votes
2
answers
364
views
Generate a Kirkman triple system
Given a universe of \$v\$ elements, a Kirkman triple system is a set of \$(v-1)/2\$ classes each having \$v/3\$ blocks each having three elements, so that
every pair of elements appears in exactly ...
19
votes
9
answers
1k
views
Cryptic Multiplications
Given two non-negative integers e.g. 27, 96 their multiplication expression would be 27 x 96 = 2592.
If now each digits is ...
7
votes
5
answers
406
views
Generate number set with conditions using n numbers
Generate \$T=\{T_1,...,T_x\}\$, the minimum number of \$k\$-length subsets of \$\{1,...,n\}\$ such that every \$v\$-length subset of \$\{1,...,n\}\$ is a subset of some set in \$T\$
Here, \$n > k &...
19
votes
24
answers
2k
views
Every possible pairing
Given an positive even integer \$ n \$, output the set of "ways to pair up" the set \$ [1, n] \$. For example, with \$ n = 4 \$, we can pair up the set \$ \{1, 2, 3, 4\} \$ in these ways:
\$...
17
votes
15
answers
1k
views
Enumerate all pure sets
In set theory, a set is an unordered group of unique elements. A pure set is either the empty set \$\{\}\$ or a set containing only pure sets, like \$\{\{\},\{\{\}\}\}\$.
Your challenge is to write a ...
21
votes
24
answers
3k
views
Consecutive coin flips
This is a cross-post of a problem I posted to anarchy golf: http://golf.shinh.org/p.rb?tails
Given two integers \$ n \$ and \$ k \$ \$ (0 \le k \le n) \$, count the number of combinations of \$ n \$ ...
5
votes
0
answers
272
views
Sort my Cups︎︎︎︎︎︎︎︎︎︎ [closed]
I have a set of colored plastic cups. They come in four colors: green, yellow, pink, and blue. When I put them on my shelf, I like to stack them in a certain pattern. Your job is, given a list of any ...
11
votes
14
answers
852
views
Increasing permutation trees
For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left ...
16
votes
13
answers
1k
views
Count alternating permutations
An alternating permutation is a permutation of the first \$ n \$ integers \$ \{ 1 ... n \} \$, such that adjacent pairs of values in the permutation alternate between increasing and decreasing (or ...
7
votes
1
answer
268
views
Find run ascending lists faster
In this question I asked you to determine if a run ascending list could be made. It was code-golf so naturally most the answers are very slow. But what if we want it to be fast. In this challenge I ...