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 ...
10
votes
Normal Subgroups of \$S_4\$
JavaScript (ES6), 23 bytes
Expects a permutation of the string "4567" and returns 0 ... ...
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 ...
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 ...
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 (...
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 ...
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). ...
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 ...
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 ...
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
...
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'...
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 (...
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 ...
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 ...
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 ...
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
...
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 ...
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!
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?
<...
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?
...
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.
...
5
votes
Count N-Rich Permutations of an Integer Sequence
JavaScript (ES6), 87 bytes
Expects (n)(array).
...
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
...
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!
...
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 ...
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 ...
5
votes
Numbers with distinct decimal digits
05AB1E, 5 4 bytes
∞€ÙÙ
Outputs an infinite list.
Try it online.
Explanation:
...
4
votes
4
votes
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!
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
permutations × 202code-golf × 171
combinatorics × 40
string × 36
math × 26
sequence × 19
array × 19
number × 18
code-challenge × 15
random × 11
decision-problem × 10
sorting × 10
cops-and-robbers × 10
quine × 9
fastest-code × 7
integer × 6
source-layout × 6
abstract-algebra × 6
number-theory × 5
game × 5
restricted-complexity × 5
graph-theory × 4
palindrome × 4
arithmetic × 3
grid × 3