Skip to main content

Questions tagged [combinatorics]

For challenges involving combinatorics.

Filter by
Sorted by
Tagged with
9 votes
2 answers
343 views

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 ...
Peter Kagey's user avatar
  • 8,165
9 votes
1 answer
381 views

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 ...
Peter Kagey's user avatar
  • 8,165
4 votes
1 answer
288 views

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 ...
Weird Glyphs's user avatar
16 votes
17 answers
1k views

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,-...
Parcly Taxel's user avatar
  • 4,749
12 votes
7 answers
2k views

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 ...
Parcly Taxel's user avatar
  • 4,749
7 votes
9 answers
1k views

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 ...
Weird Glyphs's user avatar
16 votes
12 answers
993 views

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 ...
Jonathan Allan's user avatar
15 votes
9 answers
1k views

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 ...
Wheat Wizard's user avatar
  • 103k
13 votes
13 answers
2k views

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 ...
Sophia Antipolis's user avatar
14 votes
11 answers
1k views

A Rota-Baxter word, \$w\$, is a string made of the symbols a, (, and ) such that the ...
Wheat Wizard's user avatar
  • 103k
8 votes
6 answers
1k views

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 ...
Sophia Antipolis's user avatar
2 votes
11 answers
824 views

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 ...
Sophia Antipolis's user avatar
11 votes
6 answers
1k views

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 ...
Peter Kagey's user avatar
  • 8,165
15 votes
10 answers
2k views

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 ...
Sophia Antipolis's user avatar
12 votes
6 answers
2k views

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 ...
Sophia Antipolis's user avatar
7 votes
6 answers
408 views

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. ...
Sophia Antipolis's user avatar
12 votes
10 answers
2k views

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}\$, ...
Sophia Antipolis's user avatar
7 votes
2 answers
556 views

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 ...
user119818's user avatar
  • 1,631
7 votes
12 answers
816 views

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 ...
Peter Thomas's user avatar
13 votes
9 answers
2k views

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 ...
Peter Kagey's user avatar
  • 8,165
18 votes
5 answers
1k views

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 ...
emanresu A's user avatar
  • 46.2k
5 votes
1 answer
376 views

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 ...
Fluorine's user avatar
  • 151
21 votes
4 answers
2k views

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
14 votes
13 answers
1k views

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 ...
Bubbler's user avatar
  • 79.3k
10 votes
6 answers
737 views

[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 ...
Simd's user avatar
  • 3,167
14 votes
10 answers
1k views

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 ...
Aiden Chow's user avatar
  • 14.6k
10 votes
7 answers
685 views

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 ...
user119818's user avatar
  • 1,631
19 votes
14 answers
3k views

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) = \...
alephalpha's user avatar
  • 51.9k
5 votes
3 answers
529 views

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 ...
Mardoxx's user avatar
  • 181
10 votes
3 answers
398 views

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\$ ...
Karl's user avatar
  • 871
0 votes
1 answer
435 views

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, ...
Kyle Sharp's user avatar
13 votes
15 answers
2k views

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 ...
bigyihsuan's user avatar
  • 11.5k
13 votes
11 answers
2k views

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. ...
Huỳnh Trần Khanh's user avatar
16 votes
8 answers
2k views

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}\$ ...
Jonathan Allan's user avatar
13 votes
17 answers
1k views

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 ...
Parcly Taxel's user avatar
  • 4,749
10 votes
6 answers
821 views

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 ...
Bubbler's user avatar
  • 79.3k
20 votes
10 answers
1k views

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) ...
Jonathan Allan's user avatar
20 votes
8 answers
5k views

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 ...
Peter Kagey's user avatar
  • 8,165
15 votes
14 answers
2k views

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, ...
Aiden4's user avatar
  • 2,535
15 votes
10 answers
1k views

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 ...
Parcly Taxel's user avatar
  • 4,749
5 votes
2 answers
364 views

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 ...
Parcly Taxel's user avatar
  • 4,749
19 votes
9 answers
1k views

Given two non-negative integers e.g. 27, 96 their multiplication expression would be 27 x 96 = 2592. If now each digits is ...
Domenico's user avatar
  • 2,463
7 votes
5 answers
406 views

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 &...
2FaceMan's user avatar
  • 179
19 votes
24 answers
2k views

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: \$...
pxeger's user avatar
  • 25.3k
17 votes
15 answers
1k views

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 ...
emanresu A's user avatar
  • 46.2k
21 votes
24 answers
3k views

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 \$ ...
dingledooper's user avatar
  • 23.4k
5 votes
0 answers
272 views

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 ...
Ginger's user avatar
  • 6,098
11 votes
14 answers
852 views

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 ...
Wheat Wizard's user avatar
  • 103k
16 votes
13 answers
1k views

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 ...
pxeger's user avatar
  • 25.3k
7 votes
1 answer
268 views

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 ...
Wheat Wizard's user avatar
  • 103k

1
2 3 4 5
8