Skip to main content
added 115 characters in body
Source Link
Dada
  • 8.5k
  • 1
  • 18
  • 44

##Perl, 5552 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";";@_&&f(@_=map{refmap/A/?@$_:()},@_)&&&f}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";";@_&&f(@_=map{refmap/A/?@$_:()},@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval (inside @{ } to transform the input into an array and not an arrayref) to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref},@_]}";";@_&&f(@_=map{refmap/A/?@$_:()},@_)&&&f}f(@{+eval)})' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

##Perl, 55 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref}@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(@{+eval))'

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

##Perl, 52 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval (inside @{ } to transform the input into an array and not an arrayref) to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}f(@{+eval})' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"
added 446 characters in body
Source Link
Dada
  • 8.5k
  • 1
  • 18
  • 44

##Perl, 55 bytes

Just a recursive subroutine. (usualunusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref}@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(eval@{+eval))'

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

##Perl, 55 bytes

Just a recursive subroutine. (usual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref}@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(eval)'

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

##Perl, 55 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref}@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(@{+eval))'

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"
added 446 characters in body
Source Link
Dada
  • 8.5k
  • 1
  • 18
  • 44

##Perl, 6555 bytes

The bytecount includes 64 bytes of code andJust a recursive subroutine. -n flag(usual for a Perl answer, I know..)

/\d/?push@sub f{$;[$d-1]}say"@{[grep!ref,$_:/]/@_]}";(@_=map{ref?$d--@$_:$d++for/\[|]|\d+/g;say"@$_"for@()}@_)&&&f}

Needs -n and -E flags. Don't add a final newlineCall it like that :

$ perl -nEE '/\d/?push@'sub f{$;[$d-1]}say"@{[grep!ref,$_:/]/@_]}";(@_=map{ref?$d--@$_:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1()}@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref}@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(eval)'

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

##Perl, 65 bytes

The bytecount includes 64 bytes of code and -n flag.

/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@

Needs -n and -E flags. Don't add a final newline :

$ perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

##Perl, 55 bytes

Just a recursive subroutine. (usual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep{!ref}@_]}";(@_=map{ref?@$_:()}@_)&&&f}f(eval)'

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"
Source Link
Dada
  • 8.5k
  • 1
  • 18
  • 44
Loading