# Questions tagged [permutations]

A permutation is a particular ordering of some list of objects. Problems tagged with permutation usually involve finding or generating permutations, including anagrams of text.

58 questions
Filter by
Sorted by
Tagged with
11k views

### Determine whether strings are anagrams

Challenge Given two strings, work out if they both have exactly the same characters in them. Example Input word, wrdo This returns true because they are the ...
6k views

### Random Golf of the Day #1: Shuffle an Array

About the Series I will be running a little series of code-golf challenges revolving around the theme of randomness. This will basically be a 9-Hole Golf Course, but spread out over several questions....
3k views

### Code-Golf: 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): ...
3k views

### Bit-Reversal Permutations

Your goal is to create a function or a program to reverse the bits in a range of integers given an integer n. In other words, you want to find the bit-reversal permutation of a range of 2n items, zero-...
1k views

### Prime factors buddies

Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of ...
2k views

### Manage Trash So

It's become somewhat of a tradition in PPCG that some users temporarily change their names by an anagram (a new name formed by reordering the letters of the old). Sometimes it gets difficult to find ...
2k views

### Imitate an ordering

Given two lists of numbers, a source and a pattern, reorder the source to match the relative ordering of the pattern. Any two entries of the reordered source should compare the same way as the entries ...
807 views

### Permutation Numbering

The Challenge For a given set of n integers, write a program which will output its lexicographic index. The Rules The input must only be a set of unique non-negative integers separated by spaces. ...
3k views

### Sheffle tho vawols ureund!

Given an input string, output that string with all vowels a, e, i, ...
2k views

### Decompose a permutation into cycles

There is a well-known theorem that any permutation can be decomposed into a set of cycles. Your job is to write the shortest possible program to do so. Input: Two lines. The first contains a ...
1k views

### Every Possible Cycle Length

A function (or program) which takes inputs and provides outputs can be said to have a cycle if calling the function on its own output repeatedly eventually reaches the original number. For instance, ...
2k views

This is a cops-and-robbers puzzle, the cops' thread can be found here. Your task will be to find an anagram of the provided programs in the cops' thread that performs its left inverse. Once you ...
1k views

### Parity of a Permutation

Background The parity of a permutation, as defined by wikipedia, is as follows: The sign or signature of a permutation σ is denoted sgn(σ) and defined as +1 if σ is even and −1 if σ is odd. ...
1k views

### The Strange Unsorting Machine for Nefarious Purposes

Good Evening Golfers! Your challenge is to completely unsort a series of numbers. Input Exactly 100 integers will be fed to your program. Your program may accept the input either as a file, or via ...
2k views

### Generate combinations that add up to a target value

Challenge Suppose you have a list of numbers, and a target value. Find the set of all combinations of your numbers which add up to the target value, returning them as list indices. Input and Output ...
2k views

This is the cops' thread. For the robbers' thread, click here. Cops' Task First, write a quine in a language of your choosing. Next, scramble the quine. Make sure to do this well as the robbers will ...
1k views

### Garble that string!

Given a string as input, output one or more variants of the string such that: No character is in it's original position No character is adjacent to a character that it was originally adjacent to You ...
1k views

### Random Golf of the Day #8: Shuffle an infinite list

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
1k views

### It's Anagram Quine, not just Quine!

The Task In this challenge, your task is to write a program, which takes in no input, with as many anagrams that are quine of themselves as possible. Your score will be the number of anagrams of ...
779 views

1k views

This is a cops-and-robbers challenge the Robbers' Thread can be found here Your challenge is to write a program that outputs an anagram of its source code but not the original source code itself. ...
632 views

### Cycle lengths for Perfect shuffles of decks of any size

Challenge In the shortest amount of code: Compute the length of the permutation cycle of a perfect shuffle on a deck of cards of any size n (where n ≥ 2 and n is even). Output a table of all cycle ...
11k views

### The 9 Billion Names of God

The 9 Billion Names of God is a short story by Arthur C. Clarke. It's about a group of Tibetan monks whose order is devoted to writing down all the possible names of God, written in their own alphabet....
11k views

### What are the five most powerful characters in your language?

Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 ...
2k views

### Scramble words while preserving their outlines

This is much more advanced than How to randomize letters in a word and Cambridge Transposition because of the rule about which letters may be swapped with which. A simple regex will not suffice here. ...
5k views

### Shotgun Numbers

The Shotgun numbers are a sequence with a rather simple definition but some interesting structure. Start with the natural numbers: ...
2k views

### Faro shuffle an array

A Faro shuffle is a technique frequently used by magicians to "shuffle" a deck. To perform a Faro shuffle you first cut the deck into 2 equal halves then you interleave the two halves. For example <...
2k views

### Golf an Anagram Quine

In this question I asked you to guess an anagram quine based on its output. However it looks like we don't have a question asking to golf an anagram quine yet. So your task will be to make the ...
2k views

### All possible ways to interleave two strings

I recently saw this question on stackoverflow. It's a great question, but there's one fatal problem with the question. They are asking for the best way to do it. E.g, easiest to read, most idiomatic, ...
2k views

### Find all the Anagrams!

Despite having 17 questions tagged anagrams, we still don't have this question, so here it is. Your Task You must write a program or function that, when receiving a string, prints out all possible ...
480 views

### Permutation group operation

There is a well-known bijection between the permutations of n elements and the numbers 0 to n!-1 such that the lexicographic ordering of the permutations and the corresponding numbers is the same. For ...
649 views

### Dihedral group D4 composition with custom labels

The dihedral group $D_4$ is the symmetry group of the square, that is the moves that transform a square to itself via rotations and reflections. It consists of 8 elements: rotations by 0, 90, 180, ...
4k views

### Find a binary needle in a decimal haystack

The challenge You're given: a non-empty, unsorted list h of positive integers (the haystack) a positive integer n (the needle) Your task is to return the list of all unique decimal concatenations ...
2k views

### 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 ...
1k views

### Random Golf of the Day #6: Roll a d20

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
785 views

### Spiral Permutation Sequence

We can roll up the natural numbers in a rectangular spiral: ...
630 views

### Count the number of Hankelable matrices

Background A binary Hankel matrix is a matrix with constant skew-diagonals (positive sloping diagonals) containing only 0s and 1...
2k views

### Antsy permutations

Introduction Suppose you have a ruler with numbers from 0 to r-1. You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler. The ruler is so narrow that the ant ...
3k views

### The Original Number

Guidelines Scenario John has an important number, and he doesn't want others to see it. He decided to encrypt the number, using the following steps: His number is always a non-decreasing sequence (...
831 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 searched for. ...
2k views

### Calculate Landau's function

Landau's function $g(n)$ (OEIS A000793) gives the maximum order of an element of the symmetric group $S_n$. Here, the order of a permutation $\pi$ is the smallest positive integer $k$ such ...
868 views

### Reconstruct a Permutation

Introduction Suppose that you are handed a random permutation of n objects. The permutation is sealed in a box, so you have no idea which of the ...
1k views

### Cheapo Enigma machine (Cops)

For robbers' post, Cheapo Enigma machine (Robbers) A cop's submission will consist of a program/function that accepts a single byte of data and return a single byte of data. Every possible input must ...
708 views

### Constructing an Orthogonal-Diagonal Greco-Latin Square

Consider a grid of NxN unique elements. Each element has a letter (from A to the Nth letter,...
464 views

### Riffle shuffle a string - Cops

Robbers post A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle ...
3k views

This is a cops-and-robbers puzzle the robbers' thread can be found here. Your task will be two write two programs (or functions) such that they are anagrams of each other and one performs the left ...
2k views

### Rearranging the sequence

Introduction Let's observe the following sequence (non-negative integers): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... For example, let's take the ...
1k views

### The Combinatorics of Transistor

The video game Transistor features a very interesting ability system. You collect 16 "Functions" which you can use in 16 different slots. What's interesting is that there are 3 types of slots and ...
Given some positive integer $n$ generate all derangements of $n$ objects. Details A derangement is a permutation with no fixed point. (This means in every derangement number $i$ cannot be in ...