# Tag Info

## Hot answers tagged ragged-list

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

### Flatten the Array!

JavaScript (ES6), 35 bytes Inspired by @user81655's answer: f=a=>a.map?[].concat(...a.map(f)):a
• 1,047
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

### 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
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

### 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

### Flatten the Array!

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

### Unflatten an Array

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

### Multiply numbers by their depth

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

### 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 ...
• 194k

### 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 ...
• 69.7k

### 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

### Is it a valid list?

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

### 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

### 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

### 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

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

### Sort numbers in a ragged list

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

### Re-name all identifiers to a single letter

tinylisp, 149 bytes ...
• 34.4k

### 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

### 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

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

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

### 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
Accepted

### Make a list flat

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

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

### 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

### 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

### 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