Hot answers tagged

21 votes

Swap every two elements in a list

><>, 4 3 bytes i#o Try it online! Lol, ><> ties with beats Jelly & 05AB1E. Terminates with an error. -1 thanks to @Manny Queen. How does it ...
19 votes

Nesting list with a value repeated `n` amount of times

Python 2, 33 30 bytes -3 bytes thanks to @xnor lambda n,v:eval('[v,'*n+']'*n) Try it online!
  • 18.6k
18 votes

Solve Rubik's Clock

05AB1E, 203 202 193 192 bytes ...
18 votes

Repeat List Until Longer

Python 3, 29 bytes lambda x,y:len(y)//len(x)*x+x Try it online!
  • 3,129
17 votes

Multiply numbers by their depth

Vyxal, 4 bytes ⁽L€* Try it Online! ...
  • 11.2k
16 votes
Accepted

Incrementally Increment Identical Integers

BQN, 3 bytesSBCS Perfect challenge for BQN's occurence count builtin. +⟜⊒ Run online! The modifier composes two functions. If ...
  • 55.2k
15 votes

Swap Two Values in a List

Java, 27 bytes java.util.Collections::swap Try it online!
  • 2,401
15 votes

Unsort an array

Python 3, 47 bytes lambda l:(sorted({*l},key=l.count)*2)[-len(l):] Try it online!
  • 30.8k
15 votes

Incrementally Increment Identical Integers

Python 3.8, 48 46 bytes 2-byte savings jointly contributed by Jonathan Allan and dingledooper lambda L,j=1:[n-(j:=j-1)-L.index(n)for n in L] Try it online! ...
  • 34.4k
15 votes

Compare shapeless lists

Brachylog, 3 bytes p↰ᵐ Try it online! Explanation This takes the first list as the input variable, and the second list as the output variable. The interpreter then ...
  • 36.8k
15 votes

Remove odd indices and double the even indices

brainfuck, 8 bytes ,,[..,,] Try it online!
  • 2,555
14 votes

Even sum subarrays

Python 3.8 (pre-release), 57 bytes f=lambda S,p=1:S>[]and f(S[1:])+sum((p:=p^s%2)for s in S) Try it online! Similar to brute-force method below but should have ...
  • 9,318
14 votes

Encode integers with some others

Python, 29 bytes lambda l:[x+max(l)for x in l] Try it online! Just adds the list maximum to each element, producing values greater than any in the original list. ...
  • 139k
14 votes

Print a NxN integer involute

Jelly, 13 bytes ⁸JW;ṚZ+LƲƲ2¡¡ Try it online! A nilad function or full program that takes a number from stdin and returns the 1-based involute of size n × n. How it ...
  • 66.1k
14 votes

Is it a tower permutation?

Python, 46 bytes f=lambda l:len(l)<3or min(l[:3])<l[1]*f(l[1:]) Try it online! Uses the characterization A tower permutation is one where no element is ...
  • 139k
14 votes

Alternating sums of multidimensional arrays

APL(Dyalog Unicode), 4 bytes SBCS -/⍣≡ Try it on APLgolf! Alternating sum (aka right-reduce by subtraction) along last axis -/ ...
  • 55.2k
13 votes

Unsort an array

Python 2, 57 bytes lambda l:[x for c in 1,2,1for x in set(l)if l.count(x)-c] Try it online! Iterates through the distinct elements of ...
  • 139k
13 votes

Lexicographically Smallest Decreasing Integer Partition

JavaScript (Node.js), 38 bytes -7 bytes by att and Bubbler f=n=>n?[p=.5+(n+n)**.5|0,...f(n-p)]:[] Try it online! That is, find out the smallest \$x\$ where $$ ...
  • 30.8k
13 votes

Fill in the next numbers

R, 30 bytes Or R>=4.1, 23 bytes by replacing the word function with a \. ...
  • 12.3k
13 votes

Sort numbers in a ragged list

Jelly, 3 bytes FṢṁ Try it online! How it works ...
13 votes

Scribble Pad for Nerds

Vyxal, 4 bytes ×3ø^ Try it Online! 05AB1E, 3 bytes 3$Λ Try it online!
  • 11.2k
13 votes

Reconstruct Matrix from its diagonals

Vyxal, 14 12 bytes Ṗ'L√ẇÞDf?⁼;h Try it Online! Math? Sensible methods of putting things into arrays? Programs that finish in reasonable time? Couldn't be me. Times ...
  • 23.8k
12 votes

Swap every two elements in a list

Python 3, 34 bytes f=lambda l:l and l[1::-1]+f(l[2:]) Try it online! When l is empty (which makes it falsy), return it ...
  • 7,661
12 votes

Swap every two elements in a list

Vyxal r, 2 bytes yY Try it Online! Explanation: y # Uninterleave Y # Interleave
12 votes

Swap every two elements in a list

Haskell, 22 bytes f(a:b:c)=b:a:f c f x=x Try it online!
  • 9,856
12 votes

Chunk Sort a Sequence

Jelly, 10 8 bytes 3Rṁx@JṢƙ Try it online! How it works ...
12 votes

Chunk Sort a Sequence

Ruby, 49 bytes ->l{x=5;l.chunk{441[(x+=1)%12]}.map{|a,b|b.sort}} Try it online! Literally: chunk, then sort. The magic number 441 is a bitmask with 1,2,3 ...
  • 18.6k
11 votes

Remove submatrices

APL (Dyalog Unicode), 20 bytes Anonymous infix lambda taking a and b as left and right argument. Requires 0-based indexing. <...
  • 28.4k
11 votes

Swap every two elements in a list

convey, 7 bytes I knew I should have implemented SpaceChem's flipflop operator, then this would be 5 bytes. :-) -6 byte by @Manny Queen }?{ }~1 Try it online! <...
  • 11.1k
11 votes

Floating Point indexOf

Python 2, 59 bytes f=lambda l,t,p=0:l<[t]and 1+f(l[1:],t,l[0])or(t-p)/(l[0]-p) Try it online! Outputs one-indexed. Recursively loops through the list element , ...
  • 139k

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