# Questions tagged [combinatorics]

For challenges involving combinatorics.

353 questions
Filter by
Sorted by
Tagged with
249 views

### Compute number of matrices with appropriate sums

When multiplying monomials in the Milnor basis for the Steenrod algebra, part of the algorithm involves enumerating certain "allowable matrices". Given two lists of nonnegative integers r1, ... ,rm ...
• 2,085
956 views

### Mod 2 Multinomial coefficients

quintopia has posted here a challenge to compute multinomial coefficients (some of the text here is copied from there). There is a fun algorithm to compute multinomial coefficients mod 2. Given a ...
• 2,085
383 views

### Integer triangles with perimeter less than n

Definition An "integer triangle" is one with integer coordinates. For example the following triangle is an integer triangle: ...
• 8,117
858 views

### ​L​o​o​p​ ​I​t​

Note: The title of this question should be "Loop It", but because title needs to be at least 15 characters, there are some invisible spaces. This note is such that the challenge can be ...
• 43.1k
2k views

### Is it a shuffle?

Yesterday I asked this question about riffle shuffles. It seems that yesterdays question was a bit too hard so this question is a related but much easier task. Today you are asked to determine if a ...
• 89.4k
2k views

### Single swaps of an array

Inspired by Taken from a question at Stack Overflow. The challenge Given an integer n>1, output all arrays that can be obtained by swapping exactly two entries ...
• 100k
558 views

### How many shuffles

A riffle shuffle is a type of shuffle where the deck is split into two partitions and the partitions are then spliced back together to create a new shuffled deck. The cards are spliced together in ...
• 89.4k
211 views

### Prefixless Palindromes

Write a program or function that takes N, and S and outputs the number of palindromes of length S you can build using an alphabet of size N such that any prefix of size between 2 and S-1 is not a ...
• 101
295 views

### Now we're thinking in n dimensions!

The question: Given an a number n ≥ 2, how many distinct pairs of points on an n-dimensional ...
• 1,543
845 views

### XKCD Calendar Facts

Inspiration. Posted with permission. Print one of the possible XKCD calendar "facts": You can get the raw text and structure from my APL reference implementation or from Explain XKCD's ...
• 28k
2k views

### Enumerate all possible grids of integers with constraints

Problem Consider a square 3 by 3 grid of non-negative integers. For each row i the sum of the integers is set to be r_i. ...
806 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 ...
• 14.7k
321 views

### Bobby's Booby-Trapped Safe

Bobby's booby-trapped safe requires an n-digit code to unlock it. Alex has a probe which can test combinations without typing them onto the safe. The probe responds Fail if no individual digit is the ...
• 2,723
992 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 ...
• 15.1k
597 views

### Counting Fibonacci Orbits

If we define a Fibonacci-like sequence as fk(n) = (fk(n-1) + fk(n-2)) % k, for some integer k (where % is the modulo operator), the sequence will necessarily be cyclic, because there are only k2 ...
• 194k
7k views

### Don't repeat yourself in Rock-Paper-Scissors

Upon the rumor that Codegolf will have a Rock-Paper-Scissors tournament you look into the topic of square-free words. A word made of the letters R, ...
• 1,717
641 views

### Determine How many Wheels There Are

Non-math explanation This is an explanation that is meant to be approachable regardless of your background. It does unfortunately involve some math, but should be understandable to most people with a ...
• 89.4k
2k views

### Number of distinct non-empty subsequences of binary expansion

A subsequence is any sequence that you can get from another by deleting any amount of characters. The distinct non-empty subsequences of 100 are ...
• 38.8k
195 views

### Those annoying grasshoppers [closed]

The problem #6 of IMO 2009 reads: Let a 1, a 2, a 3, ..., a n, be distinct positive integers and let T be a set of n-1positive integers not containing a 1+a 2+a 3+...+a n, A grasshopper is to ...
• 209
386 views

### Distinct Reversible Primitive Binary Necklaces

Introduction - What is a necklace? A necklace is something that OEIS people are obsessed with. The OEIS challenge has like 5 necklace sequences. A binary necklace of length ...
• 40.3k
2k views

### How many partitions do I have?

The partition number of a positive integer is defined as the number of ways it can be expressed as a sum of positive integers. In other words, the number of integer partitions it has. For example, the ...
964 views

### Restricted Integer Partitions

Pk(n) means the number of partitions of n into exactly k parts. Given n and ...
• 5,321
901 views

### How many ways can a road cross a river?

Imagine a straight river and a road that goes across the river n times through bridges. The road does not loop on itself and is infinitely long. This road would be considered an open meander. An open ...
• 16.1k
1k views

### How many partitions contain only perfect squares?

Given a non-negative integer or a list of digits, determine in how many ways can the number be formed by concatenating square numbers, which may have leading zeroes. Examples ...
• 40.3k
594 views

### Maximum number of distinct substrings

Description Given a length n, and an alphabet size k>0, your program must determine the number of strings with those ...
• 3,195
1k views

You might already be familiar with the game: Basketball FRVR in facebook. There are two types of score you can make: A virgin-shot:(we call it so in our country :D) When the ball enters the basket ...
• 2,759
396 views

### Lyndon word factorization

Background A Lyndon word is a non-empty string which is strictly lexicographically smaller than all its other rotations. It is possible to factor any string uniquely as the concatenation of Lyndon ...
• 3,195
999 views

### All non-ordered pairs between the elements of an array

Task: Return an array with all possible pairs between the elements of an array. Example From a=["a", "b", "c", "d"]; return ...
• 395
552 views

### Compute OEIS A005434

The task is to compute OEIS A005434 as quickly as possible. Consider a binary string S of length n. Indexing from ...
1k views

### How many ways to write numbers as sums of squares?

Task Given two integers $d$ and $n$, find the number of ways to express $n$ as a sum of $d$ squares. That is, $n = r_1^2 + r_2^2 + ... + r_d^2$, such that $r_m$ is an integer for all ...
• 13.6k
159 views

### Rooting for Trees With the Right Nodes

Background A rooted tree is an acyclic graph such that there is exactly one path from one node, called the root, to each other node. A node v is called the parent ...
• 16k
595 views

### Roll to see all sides!

Let's say you have a 20-sided die. You start rolling that die and have to roll it a few dozen times before you finally roll all 20 values. You wonder, how many rolls do I need before I get a 50% ...
• 12.1k
1k views

### Finding approximate correlations

Consider a binary string S of length n. Indexing from 1, we can compute the Hamming ...
190 views

### Find Subset Factors

Let's imagine we have a finite set of positive integers. This set can be represented as a line of dots where each integer present in the set is filled in like a scantron or punch card. For example ...
• 89.4k
823 views

### Maximal discrepancy-2 sequence with minimal entropy

Background As noted in the PPCG challenge Compress a maximal discrepancy-2 sequence – which inspired this challenge – the authors of the paper Computer-Aided Proof of Erdős Discrepancy Properties ...
• 207k
646 views

### Find the Odd odds

Given an unordered collection of positive integers by any reasonable input method, return all of the sub-collections that have an odd number of odd elements (i.e. have an odd total). This is code-...
• 89.4k
935 views

### Compress a maximal discrepancy-2 sequence

Output this binary sequence of length 1160: ...
• 138k
2k views

### Generate all Sublist Partitions

Given a non-empty list of integers, output every possible partitioning of the list where each partition is a non-empty sublist. So for the list [1, 2, 3, 4] the ...
• 23k
1k views

### Anaglot Polygrams

Task Write some code that can be rearranged into n different programs in n different languages each outputting a distinct number from 1 to n. No two languages should be the same however different ...
• 89.4k
1 vote
271 views

### Self Referential Puzzle - medium 2 [closed]

The following puzzle was asked in puzzling SE. This puzzle is quite hard to solve by hand because every answer depends on another answer. So, for example, a solution with all answers being A does not ...
323 views

### Greedily partition the list of combinations with repetition

First, a few definitions: Given n and k, consider the sorted list of multisets, where for each multiset we choose ...
3k views

In this challenge we try to solve two important problems at once. They are: Given integers $a$ and $b$, tell if $a^b-1$ is a prime number. Given integers $a$ and $b$, return $a\choose b$. ...
• 5,067
1k views

### Find Diffy Games

A fun game to play if you are bored is the Diffy Game. It is a one player game that is pretty simple and can consume a good deal of your time. The Diffy game works like as follows: You start with a ...
• 89.4k
3k views

### Deranged !Combinatorics: Compute the Subfactorial

The subfactorial or rencontres numbers (A000166) are a sequence of numbers similar to the factorial numbers which show up in the combinatorics of permutations. In particular the nth subfactorial !n ...
• 194k
2k views

### Count the number of Hamming distance sequences

The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. Let P be a binary string of ...
1k views

### Count how many distance sequences are far from all others

The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. Let P be a binary string of ...
1k views

### Number of string permutations that are palindromes

Your input will be a string consisting of small english letters. Your task is to determine the number of distinct permutations of the original string that are a palindrome. The input string has up ...
436 views

### Stable marriage problem

Background Suppose that there are 2*n people to be married, and suppose further that each person is attracted to exactly n ...
• 4,650
374 views

### Rafting Problem (Knapsack variant)

First puzzle from me, suggestions for improvement gladly received! The scenario is; You work as a manager for a whitewater rafting company. Every morning, you are given a list of bookings, and you ...
• 303