12 votes

How many sorting networks?

Rust, \$n = 6\$ in ≈ 59 seconds The main simplifying observation here is that we don’t need to run the network on all \$n!\$ permutations; it suffices to run it on all \$2^n\$ binary strings. We can ...
Anders Kaseorg's user avatar
10 votes

Normal Subgroups of \$S_4\$

JavaScript (ES6), 23 bytes Expects a permutation of the string "4567" and returns 0 ... ...
Arnauld's user avatar
  • 186k
9 votes

Generate a permutation from the high-water marks

Nibbles, 5 bytes .,@?:-,_@@ Attempt This Online! Puts the \$k\$ highest numbers at the specified indices in ascending order and the remaining numbers at the ...
xigoi's user avatar
  • 7,093
9 votes

Numbers with distinct decimal digits

Haskell, 37 bytes import Data.List nub$nub.show<$>[1..] Try it online! Takes each number, removes duplicate digits from its string representation while ...
xnor's user avatar
  • 144k
8 votes

Character insertion on letterboards

Jelly, 8 bytes ŒPUṚ;"Ɗi Try it online! Takes the letter-list \$\sigma\$ on the left and the target word \$S\$ on the right, returning a non-negative integer (...
Unrelated String's user avatar
8 votes

CGAC2022 Day 6: Shuffles with specific "magic number"

J, 26 22 bytes ((=#"1-#@C.)#])!A.&i.] Try it online! -4 thanks to Bubbler! Generates all perms, converts to cycle representation, take sum of "length ...
Jonah's user avatar
  • 32.4k
8 votes

First odd then even indices

K (ngn/k), 12 bytes #{x@<2!!#x}\ Try it online! { ... }\ Iterate until reaching the first value again (or a fixed point). ...
ovs's user avatar
  • 57.8k
8 votes

First odd then even indices

Thunno 2 L, 4 bytes µ¥zS Try it online! or verify all test cases µ¥zḞ Try it online! or ...
The Thonnu's user avatar
  • 17.5k
7 votes

Normal Subgroups of \$S_4\$

Python NumPy, 26 bytes lambda A:(2*A-A@A).trace() Attempt This Online! Uses as the four distinct items the vectors ...
Albert.Lang's user avatar
  • 1,889
7 votes

Count N-Rich Permutations of an Integer Sequence

Husk, 9 bytes #mȯ▲mLġ>P Try it online! or Try the test lists with N=2 ...
Dominic van Essen's user avatar
7 votes

First odd then even indices

J, 26 24 bytes i.~_:0}(\:2|#\)^:(3<@^#) Try it online! Accepts numeric lists The maximum number of iterations until we return to the input is bounded by Landau'...
Jonah's user avatar
  • 32.4k
6 votes

Normal Subgroups of \$S_4\$

J, 14 bytes 5|1#.2^~#@>@C. Attempt This Online! Found while experimenting with the cycle decomposition of each permutation. Category 1 (...
Bubbler's user avatar
  • 72.7k
6 votes

Generate a permutation from the high-water marks

R, 23 bytes Edit: -9 bytes thanks to Command Master by switching to use a bitmask as input function(h)rank(h,,"f") Try it online! Input is simply a ...
Dominic van Essen's user avatar
6 votes

How many sorting networks?

Rust, \$n=6\$ in roughly 50 48 43 41 23 seconds. Thanks to @AnttiP for a 44% speedup! My solution is based off of @AndersKaseorg's solution. I originally posted my changes as comments there, but with ...
isaacg's user avatar
  • 41.7k
6 votes

How many sorting networks?

Rust, n=6 in ~12 1 second This answer is based on @Anders Kaseorg's solution and uses some of @isaacg's improvements. I got the answer 1,530,608,978,810 for n=7 in about 12 hours using more than 100 ...
gsitcia's user avatar
  • 2,521
6 votes

First odd then even indices

Jelly, 6 bytes ŒœẎ$ƬL Try it online! Don't worry, the stack languages with single-byte uninterleave operators are going to be even shorter :P ...
Unrelated String's user avatar
6 votes

Numbers with distinct decimal digits

J, 14 bytes ~.~.@":&>i.!14 Attempt This Online! (with 7 instead of 14) Uses xnor's idea: take unique digits from each number and then take unique ...
Bubbler's user avatar
  • 72.7k
5 votes

CGAC2022 Day 6: Shuffles with specific "magic number"

Python 3, 108 bytes f=lambda n,k,*a:n and sum([f(n-1,k-1,v,*a[:i],n,*a[i+1:])for i,v in enumerate(a)],f(n-1,k,n,*a))or[a]*(k==0) Try it online!
tsh's user avatar
  • 33.6k
5 votes

Generate a permutation from the high-water marks

Jelly,  4  2 bytes ỤỤ A monadic Link that accepts a bitmask identifying the high watermarks and yields a permutation. Try it online! Or see the test-suite. How? <...
Jonathan Allan's user avatar
5 votes

Find Unique Anagrams

Jelly, 4 bytes Ṣ€Ḣƙ A monadic Link that accepts a list of lists and yields a list of lists containing the first of each anagram. Try it online! How? ...
Jonathan Allan's user avatar
5 votes

Count N-Rich Permutations of an Integer Sequence

Ruby, 85 79 77 bytes Misread the prompt at first and was returning the permutations themselves instead of the amount, whoops. ...
Value Ink's user avatar
  • 12.4k
5 votes

Count N-Rich Permutations of an Integer Sequence

JavaScript (ES6), 87 bytes Expects (n)(array). ...
Arnauld's user avatar
  • 186k
5 votes

Count N-Rich Permutations of an Integer Sequence

Thunno 2 L, 10 bytes qæƑœØ^ḷG¹= Try it online! or verify all test cases Explanation ...
The Thonnu's user avatar
  • 17.5k
5 votes

Count N-Rich Permutations of an Integer Sequence

Wolfram Language (Mathematica), 62 57 bytes Port of @chunes's Factor code in Mathematica. Saved 5 bytes thanks to the comment of @ZaMoC Golfed version. Try it online! ...
138 Aspen's user avatar
  • 4,047
5 votes

First odd then even indices

05AB1E, 8 bytes vDÅ≠})Ùg Try it online or verify all test cases (the test suite uses the faster alternative ι˜ instead of ...
Kevin Cruijssen's user avatar
5 votes

First odd then even indices

Google Sheets, 107 bytes =let(d,torow(A:A,3),_,lambda(_,a,n,sort(let(b,torow(wrapcols(a,2),3),if(and(b=d),n,_(_,b,1+n))))),_(_,d,1)) Put the input in cells ...
doubleunary's user avatar
5 votes

Numbers with distinct decimal digits

05AB1E, 5 4 bytes ∞€ÙÙ Outputs an infinite list. Try it online. Explanation: ...
Kevin Cruijssen's user avatar
4 votes

Permutapalindromic numbers

Japt, 13 bytes _ì á fÎdêQ}iU Try it 0-indexed ...
Kamil Drakari's user avatar
4 votes

Is this a Permutation of 1..n

TypeScript's Type System, 450 442 bytes ...
LeoDog896's user avatar
  • 295
4 votes

Character insertion on letterboards

Python 3, 68 65 bytes f=lambda s,x,a="":x and f(s,y:=x[1:],x[0]+a)|f(s,y,a+x[0])or a==s Try it online!
97.100.97.109's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible