42 votes
Accepted

Flatten the Array!

K, 3 bytes ,// This is a fairly common idiom. "Join over converge". try it here with oK. How it works: Join (,) fuses ...
  • 4,962
39 votes

Flatten the Array!

JavaScript (ES6), 35 bytes Inspired by @user81655's answer: f=a=>a.map?[].concat(...a.map(f)):a
  • 1,047
38 votes
Accepted

Is it true? Ask Jelly!

Jelly, 3 bytes ṭFẠ F flattens the input list. tacks on the original input list as an ...
  • 3,654
26 votes

Unflatten an Array

JavaScript, ES6, 44 bytes f=(a,b,i=0)=>a.map(x=>x.map?f(x,b,i):b[i++]) This creates a function f which can be called like ...
  • 26.3k
21 votes
Accepted

Determine the depth of an array

K, 4 bytes #,/\ In K, ,/ will join all the elements of a list. The common idiom ,// ...
  • 4,962
19 votes

Unflatten an Array

JavaScript, ES6, 41 bytes I was really impressed by Optimizer's answer, it was very cleverly done and I learned a lot. However on looking it over I found a way of shortening it slightly and fixing a ...
  • 309
19 votes

Flatten the Array!

Mathematica, 16 14 bytes {##&@@#&//@#}& An unnamed function which takes and returns a list, e.g.: ...
18 votes

Unflatten an Array

Dyalog APL, 14 characters This is a no-brainer: (∊a)←b. Normally, ∊a means a flattened, but ...
  • 14.9k
17 votes

Multiply numbers by their depth

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

Is it true? Ask Jelly!

Retina, 10 bytes A`\b0 ^... Try it online! First we remove the input if it contains a zero. The we try to match at least three characters from the beginning of ...
15 votes

Determine the depth of an array

Retina, 10 Saved 1 byte thanks to @ӍѲꝆΛҐӍΛПҒЦꝆ Saved 14 extra bytes thanks to @MartinBüttner +`\w|}{ { Here the input format is a bit contrived - _ characters ...
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
14 votes

Is it a valid list?

JavaScript, 10 bytes JSON.parse Outputs via the presence or absence of an error. Try it online!
  • 2,421
13 votes

Flatten the Array!

Python 2, 43 bytes f=lambda l:[l]*(l*0!=[])or sum(map(f,l),[]) On a list, recurses on the elements and concatenates the results. On a string or number, encases ...
  • 139k
13 votes

B​u​i​l​d a n​e​s​t

Python, 153 128 bytes s=l=0;r="";n=input() for d in bin(n)[2:]*(n>0):c=d<"1";l=[l,s>1][c];r+="]"*c+(1-l*c)*"[";s+=1-c-l*c print"["+r+"["*l+"]"*(s+l+1) ...
  • 38.8k
13 votes

Find the "Recursive Size" of a List

Python, 42 bytes f=lambda x:x*0==[]and len(x)+sum(map(f,x)) For a non-list, output 0. For a list, output its length plus the sum of the recursive outputs for its ...
  • 139k
13 votes

cadaddadadaddddaddddddr - linked list accessing

JavaScript (V8), 48 bytes a=>f=b=>b[2]?b[[x,...r]=f(b.slice(1)),1]<f?x:r:a Try it online! -2 bytes thanks to @Arnauld!
  • 11.1k
13 votes

Sort numbers in a ragged list

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

Re-name all identifiers to a single letter

tinylisp, 149 bytes ...
  • 34.4k
12 votes

Determine the depth of an array

Python 2, 33 bytes f=lambda l:l>{}and-~max(map(f,l)) Recursively defines the depth by saying the depth of a number is 0, and the depth of a list is one more ...
  • 139k
12 votes

Unflatten an Array

Python 2, 50 f=lambda s,v:v.pop(0)if s<[]else[f(x,v)for x in s] This was a very beautiful problem. As I kept working on it, I kept realizing that bits of my ...
  • 139k
12 votes

B​u​i​l​d a n​e​s​t

Python 2.7, 172 149 124 118 bytes ...
  • 1,958
12 votes

Is it true? Ask Jelly!

Ruby, 25 24 23 18 16 bytes p$_!~/\D0|^..$/ Requires the -n flag on the command line (+1 byte, ...
  • 70.7k
12 votes
Accepted

Make a list flat

Languages with built-ins HBL, 0.5: - - Try it online! Fig, ~0.823: f - Try it online! flax, 1: ...
11 votes

cadaddadadaddddaddddddr - linked list accessing

Python 3, 68 66 54 bytes lambda r,s:eval(s[:0:-1].translate(["[1:]","[0]"]*51)) Try it online! Alt, similar idea (which works in Python 2): ...
  • 1,241
11 votes

Reconstruct a recursively prime-encoded integer

Python 2, 42 bytes Thanks to @tsh for suggesting a 2-byte improvement f=lambda x=1,*a:x<2or-(x*-1or~f(*x))*f(*a) Try it online! ...
  • 18.6k
11 votes

Find the maximum length in a ragged list

Python 2, 40 bytes f=lambda a:a>[]and max(len(a),*map(f,a)) Attempt This Online! Uses Python 2's global ordering: lists are all considered greater than ints. We can also use ...
  • 22.6k
11 votes

Compare shapeless lists

Python 3, 49 bytes lambda x,y:g(x)==g(y) g=lambda a:sorted(map(g,a)) Try it online!
  • 40.3k
11 votes

Make a list flat

Python 2, 39 bytes f=lambda s:[s]*(s<f)or sum(map(f,s),[]) Attempt This Online! Found independently but very similar to @xnor's answer to the linked question.
10 votes

Unflatten an Array

Python, 51 f=lambda a,b:[b.pop(0)if x<[]else f(x,b)for x in a] Example: ...
  • 19k

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