# 离开巢穴

23

## 例子

``````[1, 2, [3, [4, 5], 6, [7, [8], 9]]] => [[1, 2], [3, 6], [4, 5, 7, 9], [8]]

[3, 1, [12, [14, [18], 2], 1], [[4]], 5] => [[3, 1, 5], [12, 1], [14, 2, 4], [18]]

[2, 1, [[5]], 6] => [[2, 1, 6], [5]]

[[54, [43, 76, [[[-19]]]], 20], 12] => [[12], [54, 20], [43, 76], [-19]]

[[[50]], [[50]]] => [[50, 50]]
``````

5

# 珀斯，17岁

`````` us-GeaYsI#GQ)S#Y
``````

`````` us-GpWJsI#GJQ)
``````

### 扩张：

`````` us-GeaYsI#GQ)S#Y     ##   Q = eval(input)
u          Q)        ##   reduce to fixed point, starting with G = Q
sI#G          ##   get the values that are not lists from G
##   this works because s<int> = <int> but s<list> = flatter list
aY              ##   append the list of these values to Y
e                ##   flatten the list
-G                 ##   remove the values in the list from G
S#Y     ##   remove empty lists from Y
``````

5

# Mathematica，56 54 52字节

``````Cases[#,_?AtomQ,{i}]~Table~{i,Depth@#}/.{}->Nothing&
``````

1
`Cases[#,_?AtomQ,{i}]~Table~{i,Depth@#}~DeleteCases~{}&`
alephalpha

1
`Cases[#,_?AtomQ,{i}]~Table~{i,Depth@#}/.{}->Nothing&`，短2个字节
CalculatorFeline

1

# 视网膜，79

``````{([^{}]+)}(,?)([^{}]*)
\$3\$2<\$1>
)`[>}],?[<{]
,
(\d),+[<{]+
\$1},{
<+
{
,*[>}]+
}
``````

1

# Mathematica 55 64 62字节

``````#~Select~AtomQ/.{}->Nothing&/@Table[Level[#,{k}],{k,Depth@#}]&
``````

``````%&[{1, 2, {3, {4, 5}, 6, {7, {8}, 9}}}]
``````

{{1，2}，{3，6}，{4，5，7，9}，{8}}

1

# JavaScript，112 80字节

``F=(a,b=[],c=0)=>a.map(d=>d!==+d?F(d,b,c+1):b[c]=[...b[c]||[],d])&&b.filter(d=>d)``

1

@Neil `d[0]?`将评估`false`它是否等于`0`，在范围之内`[-100,100]`。所以会`d=>d`

@Neil匆匆把它扔了，所以我知道还有其他机会可以缩小它，但这比我那时做的要好得多。谢谢！哦，由于这个原因，Patrick对空检查是正确的。我去了`d===+d`，因为它在null检查中节省了2个字节。
Mwr247 '16

1
@Dendrobium无法正确处理最后一种情况（或任何带有的情况`[...,[[...]]]`
Mwr247 '16

1
@PatrickRoberts `d=>d`可以，因为那时候`d`总是数组或null，但是关于`d[0]``d.map`这是一个公平的观点，尽管总有一个数组是正确的，但对于数字却是虚假的。

1

# 果冻，24个字节

``````fFW®;©ṛ¹ḟF;/µŒḊ’\$¡W®Tị¤;
``````

``````fFṄ¹¹?ḟ@¹;/µ¹¿
``````

0

# Python，108 99字节

``````def f(L):
o=[];i=[];j=[]
for x in L:[i,j][[]<x]+=[x]
if i:o+=[i]
if j:o+=f(sum(j,[]))
return o``````

Mego 2016年

mbomb007 '16

SE Markdown将制表符转换为4个空格，因此无论如何都不会转义它们：)在Markdown中使用单个空格会使代码块的字节数实际上与代码的字节数匹配。
Mego 2016年

mbomb007 '16

0

## Python 3，109个字节

``````def d(s):
o=[]
while s:
l,*n=[],
for i in s:
try:n+=i
except:l+=[i]
if l:o+=[l]
s=n
return o``````

0

# Perl，63个字节

``````{\$o[\$x++]=[@t]if@t=grep{!ref}@i;(@i=map{@\$_}grep{ref}@i)&&redo}
``````

``````@i=[[54, [43, 76, [[[-19]]]], 20], 12];                              # input

{\$o[\$x++]=[@t]if@t=grep{!ref}@i;(@i=map{@\$_}grep{ref}@i)&&redo}      # the snippet

use Data::Dumper;                                                    # print output
\$Data::Dumper::Indent=0;  # keep everything on one line
\$Data::Dumper::Terse=1;   # don't print \$VAR =
print Dumper(\@o);
``````

``````[[12],[54,20],[43,76],[-19]]
``````

0

## Clojure，119个字节

（带有seq？的116，并以列表形式输入，进行了细微的修改）

``````(defn f([v](vals(apply merge-with concat(sorted-map)(flatten(f 0 v)))))([l v](map #(if(number? %){l[%]}(f(inc l)%))v)))
``````

``````(defn f([v]  (vals(apply merge-with concat(sorted-map)(flatten(f 0 v)))))
([l v](map #(if(number? %){l[%]}(f(inc l)%))v)))
``````

``````(f [[54, [43, 76, [[[-19]]]], 20], 12])
([12] (54 20) (43 76) [-19])
``````

0

## 球拍259字节

``````(let((ol'())(m 0))(let p((l l)(n 0))(cond[(empty? l)][(list?(car l))(set! m(+ 1 n))
(p(car l)(+ 1 n))(p(cdr l)n)][(set! ol(cons(list n(car l))ol))(p(cdr l)n )]))
(for/list((i(+ 1 m)))(flatten(map(λ(x)(cdr x))(filter(λ(x)(= i(list-ref x 0)))(reverse ol))))))
``````

``````(define (f l)
(define ol '())
(define maxn 0)
(let loop ((l l)              ; in this loop each item is added with its level
(n 0))
(cond
[(empty? l)]
[(list? (first l))
(loop (rest l) n)]
[else
(set! ol (cons (list n (first l)) ol))
(loop (rest l) n )]))

; now ol is '((0 1) (0 2) (1 3) (2 4) (2 5) (1 6) (2 7) (3 8) (2 9))

(for/list ((i (add1 maxn)))   ; here similar levels are combined
(flatten
(map (λ (x) (rest x))      ; level numbers are removed
(filter (λ (x) (= i(list-ref x 0)))
(reverse ol))))))
``````

``````(f '[1 2 [3 [4 5] 6 [7 [8] 9]]])
``````

``````'((1 2) (3 6) (4 5 7 9) (8))
``````

0

# MATL，37字节

``````j']['!=dYsXKu"GK@=)'[\[\],]'32YXUn?1M
``````

``````j            % read input as string (row array of chars)
']['!        % 2x1 array containing ']'  and '['
=            % test for equality, all combinations
d            % row array obtained as first row minus second row
Ys           % cumulative sum. Each number is a nesting level
XK           % copy to clibdoard K
u            % unique values: all existing nesting levels
"            % for each nesting level
G          %   push input
K          %   push array that indicates nesting level of each input character
@          %   push level corresponding to this iteration
=          %   true for characters corresponding to that nesting level
)          %   pick those characters
'[\[\],]'  %   characters to be replaced
32         %   space
YX         %   regexp replacement
U          %   only numbers and spaces remain: convert string to array of numbers
n?         %   if non-empty
1M       %     push that array of numbers again
%   end if implicitly
% end for each implicitly
``````