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 ...
JohnE's user avatar
  • 5,062
39 votes

Flatten the Array!

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

Is it true? Ask Jelly!

Jelly, 3 bytes ṭFẠ F flattens the input list. tacks on the original input list as an ...
hvd's user avatar
  • 3,664
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 ,// ...
JohnE's user avatar
  • 5,062
19 votes

Flatten the Array!

Mathematica, 16 14 bytes {##&@@#&//@#}& An unnamed function which takes and returns a list, e.g.: ...
Martin Ender's user avatar
17 votes

Multiply numbers by their depth

Vyxal, 4 bytes ⁽L€* Try it Online! ...
naffetS's user avatar
  • 12.3k
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 ...
Martin Ender's user avatar
16 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: ...
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 ...
Digital Trauma's user avatar
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 ...
Fatalize's user avatar
  • 38.5k
14 votes

Is it a valid list?

JavaScript, 10 bytes JSON.parse Outputs via the presence or absence of an error. Try it online!
Unmitigated's user avatar
  • 2,749
14 votes

Re-name all identifiers to a single letter

tinylisp, 149 bytes ...
DLosc's user avatar
  • 38.4k
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 ...
xnor's user avatar
  • 144k
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) ...
orlp's user avatar
  • 39.1k
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 ...
xnor's user avatar
  • 144k
13 votes

Sort numbers in a ragged list

Jelly, 3 bytes FṢṁ Try it online! How it works ...
caird coinheringaahin g's user avatar
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 ...
xnor's user avatar
  • 144k
12 votes

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

Python 2.7, 172 149 124 118 bytes ...
Linus's user avatar
  • 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, ...
Doorknob's user avatar
  • 71.4k
12 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!
user81655's user avatar
  • 11.2k
12 votes

Ragged list pattern matching

Elixir, 1 byte = Yes, Elixir's equality/pattern match operator functions exactly as requested when input is provided as plain code with wildcards indicated by ...
Kirill L.'s user avatar
  • 13.9k
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): ...
kops's user avatar
  • 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! ...
dingledooper's user avatar
  • 22.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 ...
pxeger's user avatar
  • 23.5k
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!
hyper-neutrino's user avatar
  • 41.4k
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.
Albert.Lang's user avatar
  • 2,539
10 votes

Reverse an N-Dimensional array

Pyth, 11 - 50% = 5.5 bytes L?+IbY_yMbb Try it online: Demonstration or Test Suite. This defines a function y. The additional ...
Jakube's user avatar
  • 21.9k
10 votes

Flatten the Array!

Ruby, 43 42 34 bytes Recursive solution. Now with exception handling! (might as well credit @akostadinov for inspiring the change though) ...
Value Ink's user avatar
  • 12.5k
10 votes

Scan a ragged list

Python, 57 54 53 bytes f=lambda x,a=0:[i*0==0and(a:=a+i)or f(i,a)for i in x] Attempt This Online! Thanks to @ovs for -3 bytes. Whython, 42 bytes f=lambda x,a=0:[(a:=a+i)?f(i,a)for i in x] Attempt This ...
pxeger's user avatar
  • 23.5k
10 votes

Sort numbers in a ragged list

Ruby, 51 47 bytes ->l{eval"#{l}".gsub(/\d+/,'%d')%l.flatten.sort} Try it online! -4 bytes thanks to Sisyphus
G B's user avatar
  • 21.6k

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