# combinatorics's questions - English 1answer

214 combinatorics questions.

### 15 The Unique Padlock PIN List!

27 answers, 3.308 views code-golf combinatorics
Introduction In a private chat, a friend of mine apparently recently stumbled across a security system which has the following two restrictions on its valid pins: Each digit must be unique (that is "...

### 13 Fun with strings and numbers

12 answers, 1.349 views code-golf string number random combinatorics
Here's a programming puzzle for you: Given a list of pairs of strings and corresponding numbers, for example, [[A,37],[B,27],[C,21],[D,11],[E,10],[F,9],[G,3],[H,2]], output another list which will ...

### 19 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 S=4 and R∊{6,8,13}. A hand of H cards is dealt from the deck. Its distribution, a.k.a. "hand ...

### 18 Fewest disk writes to defrag multiple files

Introduction A disk is a linear container with blocks indexed 0 through size-1. A file is a named list of block indexes used by that file. An example filesystem is expressed like this: 15 ALPHA=3,...

### 10 Cartesian product of a list with itself n times

When given a a list of values and a positive integer n, your code should output the cartesian product of the list with itself n times. For example, in pseudocode your function could be similar to: ...

### 24 Sign-Swapping Sums

30 answers, 1.898 views code-golf math combinatorics
Given a nonempty list of positive integers [X, Y, Z, ...], your job is to determine the number of unique values of ± X ± Y ± Z ... For example, consider the list [1, 2, 2]. There are eight possible ...

### 21 Print all colorings of a 3x3 grid

You have a 3x3 grid. Each cell can be colored black or white. Display all 512 of these colorings. Fewest bytes wins. You can display the grids in any formation as long as they are visually separated ...

### 12 Dobble/SpotIt card generator

1 answers, 1.923 views code-golf game combinatorics set-partitions
Introduction Dobble/SpotIt is a card game, where people have to spot same symbol on pair of cards in shortest time, indicate it and move to next pair. Each card has multiple symbols (8 in normal ...

### 13 Generate all combinations of given list of elements, sorted

14 answers, 934 views code-golf combinatorics
Make a code that takes a list and a number as input, and generates all possible combinations with the length of the number. For example, with the list {0,1} and the number 2: 00 01 10 11 Your ...

### 27 Case Permutation

23 answers, 1.537 views code-golf string combinatorics
Who needs to compare things case insensitively when you're able to generate every permutation of uppercase and lowercase? No one! That's the answer. No one does. Your task is to achieve this feat; ...

### 26 Absolute Sums of Sidi Polynomial Coefficients

11 answers, 2.408 views code-golf math sequence combinatorics polynomials
Background The Sidi polynomial of degree n – or the (n + 1)th Sidi polynomial – is defined as follows. The Sidi polynomials have several interesting properties, but so do their coefficients. The ...

### 21 Shortest power set implementation

33 answers, 2.483 views code-golf array-manipulation combinatorics
Problem definition Print out the powerset of a given set. For example: [1, 2, 3] => [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] Each element is to be printed on a separate line, so ...

### 14 Deranged Rearrangements

Your task is to write a computer program such that when it is cut up into lines (split on the newline character) every arrangement of the lines will output a different number between 1 and n! (where n ...

### 8 Count the number of ways of putting balls into bins

4 answers, 482 views code-golf combinatorics
In this task you are given an odd number of white balls and the same number of black balls. The task is to count all the ways of putting the balls into bins so that in each bin there is an odd number ...

### 20 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 ...

### 17 Code-Golf: Permutations

21 answers, 2.093 views code-golf combinatorics permutations
Write a function that takes as input a set of integers (can be a list, array or any other container with distinct numbers), and outputs the list of all its permutations. Python (95 chars): p=lambda ...

### 14 Permutations such that no k+2 points fall on any polynomial of degree k

1 answers, 271 views math sequence combinatorics fastest-code
Description Let a permutation of the integers {1, 2, ..., n} be called minimally interpolable if no set of k+2 points (together with their indices) fall on a polynomial of degree k. That is, No ...

### 28 Motzkin Numbers

The nth Motzkin Number is the number of paths from (0, 0) to (n, 0) where each step is of the form (1, -1), (1, 0) or (1, 1), and the path never goes below y = 0. Here's an illustration of these ...

### 2 All non-empty finite sets of positive integers

6 answers, 293 views code-golf math number combinatorics
The challenge is to create an iterator(/generator) which iterates (in any order so as to reach all of them... ie no set should occur at infinity) over all possible non-empty finite sets(/tuples/lists) ...

### 21 Random ASCII Art of the Day #5: Diamond Tilings

5 answers, 1.436 views code-golf ascii-art combinatorics random tiling
Mash Up Time! This is instalment #5 of both my Random Golf of the Day and Optimizer's ASCII Art of the Day series. Your submission(s) in this challenge will count towards both leaderboards (which you ...

### 19 Necklace splitting problem

4 answers, 1.109 views code-golf math combinatorics
Background I was inspired by 3Blue1Brown's recent video about the necklace splitting problem (or as he calls it, the stolen necklace problem) and its relationship to the Borsuk-Ulam theorem. In this ...

### 3 Count stacking sequences [duplicate]

2 answers, 73 views code-golf combinatorics counting
Given a list of stack heights, calculate the number of ways those heights could have been arrived at by stacking blocks one at a time. Shortest code wins. Test cases: [2, 2] 6 [3,3,3] 1680 [1,5,9,1] ...

### 21 Calculate a Pedigree

1 answers, 558 views code-golf combinatorics
A little genetics lesson When you only have access to someone's visible traits or phenotype, a pedigree of their family history is often used to figure out the actual genetic information or, genotype ...

### 15 Counting polystrips

1 answers, 270 views code-golf combinatorics polyomino
Polystrips are a subset of polyominoes conforming to the following rules: each piece consist of 1 or more cells no cell can have more than two neighbours the cells should not enclose a hole Free ...

### 21 ​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 searched for. ...

### 8 Sum of combinations with repetition

Write the shortest code you can solving the following problem: Input: An integer X with 2 <= X and X <= 100 Output: Total combinations of 2, 3, and 5 (repetition is allowed, order matters) ...

### 17 Enumerate all possible grids of integers with constraints

10 answers, 1.585 views code-golf combinatorics
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. Similarly for each column j the sum of integers in that column is set to be ...

### 17 Conjugate permutations

A permutation of size n is a reordering of the first n positive integers. (meaning each integer appears once and exactly once). Permutations can be treated like functions that change the order of a ...

### 32 Generate Pascal's triangle

45 answers, 5.346 views code-golf math combinatorics
Pascal's triangle is generated by starting with a 1 on the first row. On subsequent rows, the number is determined by the sum of the two numbers directly above it to the left and right. To ...

### 19 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 ...

### 36 Catalan Numbers

The Catalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics. The nth Catalan number is the number of Dyck words (balanced strings of parenthesis or brackets such as ...

### 8 Alice's Tea Party

6 answers, 407 views code-golf combinatorics
There are n places set around a circular table. Alice is sat on one of them. At each place, there's a cake. Alice eats her cake, but it doesn't taste very nice. Then the Mad Hatter comes in. He gives ...

### 7 Chess960 position lookup

10 answers, 542 views code-golf combinatorics chess
This is a follow-up to Chess960 position generator. In Chess960, there are 960 possible starting positions that can be enumerated from 0 to 959 (or, at your choice, from 1 to 960). The enumeration ...

### 14 Mod 2 Multinomial coefficients

16 answers, 846 views code-golf math combinatorics
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 ...

### 25 Compute the multinomial coefficient

16 answers, 1.442 views code-golf math combinatorics
Time for another easy challenge in which all can participate! The multinomial theorem states: The expression in parentheses is the multinomial coefficient, defined as: Allowing the terms ki to ...

### 23 Find The Rank Of A Word

Definition The rank of a word is defined as the position of the word when all the possible permutations (or arrangements) of its letters are arranged alphabetically, like in a dictionary, no matter ...

### 12 Compute number of matrices with appropriate sums

4 answers, 224 views code-golf math combinatorics
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 ...

### 33 Every word from babab to zyzyz

Your task is to write a program that will output a readable list of every five letter words with the structure: consonant - vowel - consonant - vowel - consonant The output should be sorted ...

### 15 XKCD Calendar Facts

9 answers, 621 views code-golf string random combinatorics
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 transcript (...

### 13 Integer triangles with perimeter less than n

5 answers, 295 views code-golf sequence geometry combinatorics
Definition An "integer triangle" is one with integer coordinates. For example the following triangle is an integer triangle: (0, 0), (0, 1), (1, 2) with perimeter 1 + sqrt(2) + sqrt(5) ≈ 4.650. ...

### 18 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 ...

### 19 Single swaps of an array

23 answers, 1.675 views code-golf number combinatorics integer
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 in the array [1, 2, ..., n]. The ...

### 31 Longest domino chain

Challenge description Dominoes is a game played with tiles with two values on it - one on the left, one on the right, for example [2|4] or [4|5]. Two tiles can be joined together if they contain a ...

### 7 Prefixless Palindromes

4 answers, 200 views code-golf string combinatorics
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 ...

### 15 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 ...

### 23 List all ordered partitions of n

The challenge is to list all ordered partitions (composition (combinatorics)) of a given positive integer n. These are the lists of numbers from 1 to n whose sum is n. For example, given input n = 4, ...

### 22 Calculate the partitions of N

Your challenge is simple: GIven an integer N, ouput every list of positive integers that sums to N. For example, if the input was 5, you should output [1, 1, 1, 1, 1] [1, 1, 1, 2] [1, 1, 3] [1, 2, 2]...

### 10 Generate combinations with replacement

13 answers, 928 views code-golf combinatorics
List all of the combinations with replacement (or combinations with repetition) of size k from a set of n elements. A combination with replacement is an unordered multiset that every element in it ...

### 19 Sums of prime factors

2013 has the prime factorization 3*11*61. 2014 has the prime factorization 2*19*53. An interesting property regarding these factorizations is that there exist distinct primes in the factorizations of ...

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

4 answers, 259 views code-golf combinatorics
The question: Given an a number n ≥ 2, how many distinct pairs of points on an n-dimensional n x n x n x n x n x n ... x n lattice, where the coordinates range from 0 to n - 1, are a distance at least ...