-5
\$\begingroup\$

This question already has an answer here:

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!

\$\endgroup\$

marked as duplicate by Morgan Thrapp, mbomb007, acrolith, xnor code-golf Oct 6 '16 at 18:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    \$\begingroup\$ Isn't it just counting the number of [? \$\endgroup\$ – Morgan Thrapp Oct 6 '16 at 18:10
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – Morgan Thrapp Oct 6 '16 at 18:11
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – Morgan Thrapp Oct 6 '16 at 18:13
  • 4
    \$\begingroup\$ Read about patching out approaches. \$\endgroup\$ – xnor Oct 6 '16 at 18:23
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Linus Oct 6 '16 at 18:32
1
\$\begingroup\$

Jelly, 2 bytes

ŒḊ

TryItOnline

It's a single atom, the depth monad.

\$\endgroup\$
  • \$\begingroup\$ Great solution! \$\endgroup\$ – Geno Racklin Asher Oct 6 '16 at 18:25
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Retina, 2 1 bytes

]

Just Regex.

One byte to Martin Ender.

\$\endgroup\$
  • 5
    \$\begingroup\$ ] saves a byte. \$\endgroup\$ – Martin Ender Oct 6 '16 at 18:19
  • 2
    \$\begingroup\$ Invalid since the last edit \$\endgroup\$ – TuxCrafting Oct 6 '16 at 18:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.