Skip to main content

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.

Filter by
Sorted by
Tagged with
-3 votes
3 answers
151 views

Doce logf a string swapper [closed]

Challenge Take an input string \$s\$, and split it into words \$w_1, w_2, ..., w_n\$. If the amount of words is odd, then return \$s\$. Otherwise, for each word: Take the second last letter, and swap ...
kepe's user avatar
  • 943
8 votes
7 answers
746 views

9erilous 9ermutations

Note: This is an attempt at recycling guest271314's permutation question(s) There's an interesting pattern that forms when you find the differences between lexographically sorted permutations of base ...
Jo King's user avatar
  • 47.2k
11 votes
5 answers
626 views

Amidakuji (阿弥陀籤) simplification

If you have ever had any exposure to Japanese or East Asian culture you will have surely encountered the Amidakuji game: As Wikipedia explains, it is a type of lottery drawn on paper and used to ...
Tobia's user avatar
  • 5,671
23 votes
23 answers
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 ...
Delfad0r's user avatar
  • 6,266
8 votes
1 answer
411 views

What is the simplest reversible circuit that computes conjugacy of transpositions?

Reversible computation refers to computation in which little or no information is deleted. Reversible computation a major component of quantum computation, and reversible computation is potentially ...
Joseph Van Name's user avatar
8 votes
5 answers
915 views

Permutation Encoding

Write a program which can encode text to avoid reusing characters, and convert back. Both normal and encoded forms are restricted to a particular character set: the space character ...
EPICI's user avatar
  • 409
14 votes
6 answers
2k views

Code golf the best permutation

Challenge Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other. The value of a permutation ...
user avatar
15 votes
8 answers
1k views

Block Rearrangement

So your task is to take a 3x3 block where -'s mean blank spaces, and *'s mean filled spaces, for example: ...
Noah Cristino's user avatar
33 votes
21 answers
6k views

Levi-Civita symbol

The three-dimensional Levi-Civita symbol is a function f taking triples of numbers (i,j,k) each in ...
xnor's user avatar
  • 145k
25 votes
17 answers
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_{...
user avatar
18 votes
8 answers
988 views

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 ...
Wheat Wizard's user avatar
  • 98.8k
15 votes
12 answers
1k views

Stitch Together a Palindrome from Palindromic Substrings

Given a string l, find all palindromic substrings p of l (including duplicates and single ...
Magic Octopus Urn's user avatar
14 votes
8 answers
493 views

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 ...
Wheat Wizard's user avatar
  • 98.8k
8 votes
4 answers
218 views

Flattened Spiral Permutation Index

Context Consider square matrices with n columns and rows containing the first n^2 (i.e. n ...
dylnan's user avatar
  • 5,364
10 votes
2 answers
806 views

How many draws are there in Quarto?

Introduction This challenge is similar to Project Euler problems. I came up with it because I was playing a deceivingly simple board game and couldn't come up with an efficient solution to answer a ...
wvdz's user avatar
  • 227
24 votes
26 answers
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 ...
Manish Kundu's user avatar
  • 5,290
14 votes
16 answers
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 ...
soapergem's user avatar
  • 263
22 votes
3 answers
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 ...
flawr's user avatar
  • 43.8k
20 votes
5 answers
622 views

A Dance of Many Dimensions

Challenge Given a n-dimensional array of integers and a permutation of the first n natural numbers, permute the array dimensions ...
flawr's user avatar
  • 43.8k
8 votes
5 answers
413 views

Riffle shuffle a string - Robbers

Cops 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 ...
caird coinheringaahin g's user avatar
8 votes
9 answers
613 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 ...
caird coinheringaahin g's user avatar
2 votes
4 answers
162 views

String Permutations - case and order [duplicate]

Challenge For any string that is composed of alphabetical characters of any case, make a function that returns a list of all of it's variations, order and case-wise empty strings returns empty list. ...
qqq's user avatar
  • 1,606
14 votes
11 answers
609 views

N-bit Variation on Subset-Sum

For another challenge I am writing, I need to verify that test cases are solveable with bounded integers. Specifically, I need to verify the following, for a non-empty array of integers ...
user avatar
10 votes
7 answers
346 views

Days and months make years

Today's date is quite an interesting one. Let's take a look at why. The date 07/12/2017 (in DD/MM/YYYY date format) can be split ...
caird coinheringaahin g's user avatar
22 votes
8 answers
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: ...
Misha Lavrov's user avatar
  • 5,245
28 votes
29 answers
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 ...
MercyBeaucou's user avatar
  • 3,061
10 votes
6 answers
846 views

Output all distinct permutations of a vector

Challenge: Output all distinct permutations of a, potentially long, list of positive integers. You may assume that the vector has less than 1,000 numbers when testing, but the process should in ...
Stewie Griffin's user avatar
4 votes
0 answers
201 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 ...
katana_0's user avatar
  • 209
22 votes
13 answers
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 ...
Arnauld's user avatar
  • 193k
18 votes
12 answers
2k views

The Original Number (II)

This challenge is essentially identical to this one with just one difference: it is now allowed to shuffle letters anywhere in the string. Scenario John has an important number, and he doesn't want ...
Cristian Lupascu's user avatar
25 votes
37 answers
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 ...
flawr's user avatar
  • 43.8k
27 votes
5 answers
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 ...
Arthur's user avatar
  • 371
9 votes
11 answers
433 views

Construct a Permuter

For this challenge you are going to make a function (your function may be a complete program) that takes a list as input and returns a permutation of that list. Your function must obey the following ...
Wheat Wizard's user avatar
  • 98.8k
22 votes
12 answers
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: ...
Wheat Wizard's user avatar
  • 98.8k
37 votes
21 answers
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. ...
aimorris's user avatar
  • 1,401
19 votes
14 answers
4k views

Counting from 1 to n without any consecutive numbers

Goal You are given an integer n (n > 1). You must output how many permutations of the integers ...
Philippe's user avatar
  • 457
12 votes
5 answers
520 views

Smallest unused number sharing a factor

This is a pretty run of the mill question. I will define a sequence and you golf some code to output a entry given a index. The first item in the sequence is 2. The nth item in the sequence is the ...
Wheat Wizard's user avatar
  • 98.8k
10 votes
10 answers
697 views

Solve an Anagram

See also: Granma loves Ana You will be given a string of lowercase ASCII letters. Using this dictionary file (UPDATED), your task is to solve the anagram. To solve an anagram, you must output all ...
Christian Legge's user avatar
14 votes
9 answers
1k views

Find all the Anagrams, and the Subanagrams too!

This question is heavily based off this question, but should pose a number of additional difficulties. Your Task You must write a program or function that, when receiving a string, prints out all ...
Gryphon's user avatar
  • 7,235
17 votes
17 answers
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 ...
Gryphon's user avatar
  • 7,235
2 votes
0 answers
139 views

Is that string garbled? [duplicate]

Mayube recently posted Garble that string. However, humans aren't too good at checking whether a string is actually garbled or not. (Actually, that's an understatement, we are really bad at it.) So, ...
Stephen's user avatar
  • 14k
20 votes
9 answers
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 ...
Mayube's user avatar
  • 11.6k
25 votes
42 answers
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 ...
Wheat Wizard's user avatar
  • 98.8k
18 votes
10 answers
1k views

THE Magic Hexagon

There are many magic squares, but there is just one non-trivial magic hexagon, as Dr. James Grime explained, which is the following: ...
flawr's user avatar
  • 43.8k
41 votes
11 answers
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 ...
Arnauld's user avatar
  • 193k
14 votes
9 answers
1k views

Golf you an anagram for great good!

The Task In this challenge, your task is to write some code which outputs one of its anagrams chosen randomly with uniform distribution but it should never output itself. Elaboration Given no input, ...
Arjun's user avatar
  • 5,074
10 votes
5 answers
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 your ...
Arjun's user avatar
  • 5,074
23 votes
16 answers
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 ...
Martin Ender's user avatar
45 votes
16 answers
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. ...
Adám's user avatar
  • 30.4k
20 votes
6 answers
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 ...
Wheat Wizard's user avatar
  • 98.8k