Get dimension of a list

-5

0

Find out the dimension of a simple nested list:

[] -> 1
[[]] -> 2
[[[]]] -> 3
...

List taken as input, dimension as output. No counting length of strings - list manipulation and loops only. i.e. no getting the length of the input and dividing by 2.

Any language is permitted. Get golfing!

Geno Racklin Asher

Posted 2016-10-06T18:09:20.333

Reputation: 466

Question was closed 2016-10-06T18:24:35.710

3Isn't it just counting the number of [? – Morgan Thrapp – 2016-10-06T18:10:33.787

Good idea, but that is a loophole, so I will make that illegal. @MorganThrapp – Geno Racklin Asher – 2016-10-06T18:11:45.843

2@WheatWizard I'd say no, only because this doesn't actually require any parsing. Now, it's probably going to end up being a dupe of that, but it's not currently. – Morgan Thrapp – 2016-10-06T18:11:58.113

3

Okay, so I'll count the number of ]. Or divide the length of the input by 2. This challenge in its current state is trivial. The sandbox is a great place to get input on your challenges before posting them.

– Morgan Thrapp – 2016-10-06T18:13:02.453

4

Read about patching out approaches.

– xnor – 2016-10-06T18:23:15.060

2

avoid Do X without Y. In Python the len() function works for list so I could claim print len(raw_input())/2 is list manipulation, not string counting.

– Linus – 2016-10-06T18:32:40.193

Is my 1 byte Retina answer as valid as the Jelly one? – NoOneIsHere – 2016-10-06T21:21:31.747

Answers

1

Jelly, 2 bytes

ŒḊ

TryItOnline

It's a single atom, the depth monad.

Jonathan Allan

Posted 2016-10-06T18:09:20.333

Reputation: 67 804

Great solution! – Geno Racklin Asher – 2016-10-06T18:25:38.260

1

Retina, 2 1 bytes

]

Just Regex.

One byte to Martin Ender.

NoOneIsHere

Posted 2016-10-06T18:09:20.333

Reputation: 1 916

5] saves a byte. – Martin Ender – 2016-10-06T18:19:44.757

2Invalid since the last edit – TuxCrafting – 2016-10-06T18:21:26.180

1

Brain-Flak, 44 36 32 26 + 3 = 29 bytes

Try it online

([])({<({}[()()])>()}{}<>)

+3 bytes from the -a flag.

Explanation

([])                         #Push the stack height
     {<({}[()()])>()}{}      #For loop decrement by 2
    (                  <>)   #Push number of runs to the offstack

Post Rock Garf Hunter

Posted 2016-10-06T18:09:20.333

Reputation: 55 382