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

202 questions
Filter by
Sorted by
Tagged with
12k 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 permutations. Choose your ...
• 89.8k
13k 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 ...
• 1,249
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....
• 863
4k views

### Greater than less than greater than something fishy

Given a length N string of less-than and greater-than signs (<, >), insert the integers 0 through N at the start and end ...
• 89.8k
5k views

### Shotgun Numbers

The Shotgun numbers are a sequence with a rather simple definition but some interesting structure. Start with the natural numbers: ...
• 197k
3k 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. ...
• 30.4k
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 ...
• 42.7k
3k views

### Sheffle tho vawols ureund!

Given an input string, output that string with all vowels a, e, i, ...
• 38.9k
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 ...
• 193k
4k views

### Is this a Permutation of 1..n

Input a non-empty array with $n$ positive integers. Test if the input array contains every integer in $1\cdots n$. In case you prefer 0-indexed numbers, you may choose to input an array of non-...
• 34.9k
3k 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 ...
• 105k
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 (ie. ...
• 1,401
2k views

### Can you reach this number by doubling and rearranging?

Inspired by this question on Math.SE. Starting with 1 you can repeatedly perform one of the following two operations: Double the number. or Rearrange its digits ...
• 197k
7k 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....
• 197k
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 ...
• 98.8k
6k views

### Levi-Civita symbol

The three-dimensional Levi-Civita symbol is a function f taking triples of numbers (i,j,k) each in ...
• 145k
3k 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 ...
• 59.3k
3k views

### Generate a random derangement

Challenge description A "derangement" of a sequence is a permutation where no element appears in its original position. For example ECABD is a derangement of ...
• 5,652
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 ...
• 197k
5k 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 $2^n$ ...
• 16.9k
3k views

### Unsort an array

Inspired by this StackOverflow post Given a list where each element appears a maximum of 2 times, we can define it's "sortedness" as the sum of the distances between equal elements. For ...
5k views

### Output an Anagram! No Not That One!

Given a list of unique strings that are anagrams of each other, output an anagram of those words that is different from each word in the list. The strings will be alphanumeric, and there is guaranteed ...
• 3,061
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. For ...
• 98.8k
3k views

### Superpermutations

Introduction You're a criminal tasked with stealing some secret plans from the new tech startup Dejavu. You sneak in over the back wall, but find a door that requires a pin to open it. You recognize ...
• 389
3k views

### Alphabetically permute a string

Task Your goal, should you choose to accept it, is to write a program, that, given an input string (or array of characters), outputs every possible permutation of the letters in that string. I'm ...
• 569
664 views

### Bubble the brackets!

There are a few questions on this site about balancing brackets, and checking whether brackets are balanced. I propose it's now time to use those balanced brackets for something! In mathematics and ...
• 371
3k 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 ...
• 98.8k
4k views

### Reliably Broken Sort

Given a list of positive integers that contains at least 3 distinct entries, output a permutation of that list that isn't sorted in ascending or descending order. Examples ...
• 43.8k
3k views

### Codegolf the Hafnian

The challenge is to write codegolf for the Hafnian of a matrix. The Hafnian of an $2n \times 2n$ symmetric matrix $A$ is defined as: \operatorname{haf}(A) = \frac 1 {n!2^n} \sum_{\sigma \in S_{...
2k views

### The Permutation Pigeon-hole Principle

In the game of sudoku, many players like to "pencil in" possible numbers that can go in each square: The above row can be represented as an array: ...
• 14.5k
3k views

### 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 if ...
• 5,290
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, ...
• 42k
3k 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 ...
• 461
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 ...
• 145k
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): ...
• 361
2k views

### Permutapalindromic numbers

Given an integer N as input, output the Nth permutapalindromic number. A permutapalindromic number is a strictly positive ...
• 38.9k
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 ...
• 44.4k
4k views

### Encode - Shuffle - Decode

Challenge Your task is to encode an integer as a string of ASCII characters, then successfully decode it after said string has been randomly shuffled. You will write two programs/functions, which ...
• 6,266
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 ...
• 10.6k
4k views

### Number of cycles of a permutation

Consider a permutation of the integers 1, ..., n, such as this one for n = 6: ...
• 105k
1k views

### How many laps around the permutation?

Your input is an array of numbers: a permutation of $\{1, 2 \dots n\}$ for some integer $n \geq 2$. How many times must you repeat this list before you can "pick out" the numbers \\$[1, 2 ...
• 68.8k
2k 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 ...
• 197k
2k views

### Verify a Superpermutation

A superpermutation on n symbols is a string which contains every permutation of n symbols in its body. For instance, 123121321 is a superpermutation on three ...
• 2,059
1k views

### Numbers with similar powers

Given an integer p > 1, find the smallest integer q > p such that the list of exponents in the prime factorization of q is the same of that of p, no matter the order or the value of the prime ...
• 193k
3k views

### Color me a Pole

Lets say your job is to paint poles, and a client asks you to paint a pole with 4 red sections and 3 yellow sections. You can do that pretty easily as follows: ...
• 98.8k
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 ...
• 197k
1k views

### Build this pyramid

Your pyramid The pyramid I want you to build is made entirely of cubes. It has 24 layers, and the Nth layer from the top contains N2 cubes arranged in an N by N square. The pyramid looks like this: ...
• 5,245
872 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.8k
3k views