text:
Find two integers from an unordered list to sum to the input
This is a Google interview question, see here for a youtube link.
The task:
Find 2 integers from an unordered list that sum to a given integer.

Given an unordered list of integers, find 2 integers that sum
to a given value, print these 2 integers, and indicate success (exit 0). They don't need to be any particular numbers (i.e. the first 2 integers summing to the right number), any pair that sums to the value will work.
an integer is positive and greater than zero.
a list of integers can be in any data structure including a file of
integers - one integer per line.
if no integers can be found, indicate a failure (exit 1).
two integers at different positions in list must be returned. (i.e. you can't return the same number from the same position twice)

(Note: in the video, these are not exactly the requirements. The 'interviewer' changed his multiple times.)
eg.
sum2 8 <<EOF
1
7
4
6
5
3
8
2
EOF

Prints 3 and 5 and exit status is 0.
Note that in this 1,7 and 2,6 would also be allowed results.
sum2 8 <<EOF
1
2
3
4

Returns exit status 1 since no possible combo. 4,4 isn't allowed, per rule 5.

This could have been a great question if it had had a chance to shake out some of the loose ends in the Sandbox first. For instance, for something like this I would expect to write a function that returned either a falsy value or a pair of numbers.

Can same number be used two times if that sums to given value?

In the example, why is the returned pair is (3,5) and not (1,7)?

@rod, program would get to 3 and 5 before 1 and 7.

@Dead Possum, I forgot about that case.. in video it was not allowed so I'll add that requirement. Thanks.

@Neil, I don't understand what you are suggesting. Do you want a different output, either false or first 2 integers?

There are different algorithms that can be used and the one I was using found 1 and 7 first.

How can there be a "first" pair in an unordered list? That's inherently self-contradictory.

@Peter Taylor, yes, Tom and Rod directly and indirectly point that out to me and I have amended question. Sorry.

I don't know what is expected since this has been put on hold - I have responded to questions and clarified requirements and responded to each (so far) comment directly, apologetically and this resulted in 2 changes that I expect should satisfy concerns. What remains to be clarified?

And I need to add, that I did not know about Sandbox. I broke all the rules it seems.

I don't really think the exit 0/exit 1 thing is a good idea. Many languages can't exist easily like that, and it's generally allowed to exit with an error (i.e. ignore STDERR) Many golfing languages don't even have an easy way to exit by exit code I think

I believe your list is indeed ordered by not necessarily by integer values.

Could you add more examples please? For instance, [2,2] 4.

If the language doesn't allow changing the exit code, can we just throw an error?

On second thought, some answers have gone through some effort to produce exit code 1, so it may be better not to change the requirements now

Bash, 84 bytes
My implementation of (roughly) Google's engineer's solution but using bash and an input stream - not my solution, so this does not count.
while read V;do((V<$1))&&{ ((T=R[V]))&&echo $T $V&&exit;((R[$1-V]=V));};done;exit 1

Method
while we can read integer V from input stream
if less than target $1 then
if already seen $1-V then print $1-V and V and exit 0
(else) save candidate for input $1-V
exit 1

JavaScript ES6, 58 70 68 64 bytes
a=>b=>{for(i in a)if(a.includes(b-a[i],i+1))return[a[i],b-a[i]]}

Returns a pair of numbers in the form of an array if found, otherwise returns undefined, a falsy value.

f=a=>b=>{for(i in a)if(a.includes(b-a[i],i+1))return[a[i],b-a[i]]}

console.log(f([1,7,4,6,5,3,8,2])(8));
console.log(f([1,2,3,4,5,6,7,8])(8));
console.log(f([1,2,3,4])(8));
console.log(f([2,2])(4));

The example was 3, 5 but this outputs 1, 7...

@Neil, sorry, i have amended rules because I messed up. 1,7 is ok.

This doesn't really exit code 1 for invalid input. Sure, it's falsy, but not an error. I asked OP about that requirement, he may decide to remove it though.

It won't work for f([2,2] 4) ?

@cliffroot should work for that case now

Nice includes trick.

Brachylog, 9 bytes
h⊇Ċ.+~t?∧

Try it online!
Assuming I understood the challenge correctly…
Explanation
h⊇Ċ          Ċ ('couple') has two elements, and is a subset of the head of the input
  Ċ.         Output = Ċ
   .+~t?     The sum of the elements of the Output is the tail of the Input
        ∧    (disable implicit unification)

Perl 6, 59 bytes
$_=get;put lines().combinations(2).first(*.sum==$_)//exit 1

Try it
Try it with no possible result
Expanded:
$_ = get;            # get one line (the value to sum to)

put                  # print with trailing newline
    lines()          # get the rest of the lines of input
    .combinations(2) # get the possible combinations
    .first(          # find the first one
      *.sum == $_    # that sums to the input
    )
  //                 # if there is no value (｢Nil｣)
    exit 1           # exit with a non-zero value (｢put｣ is not executed)

JavaScript (ES6), 61 57 56 bytes
Takes the array of integers a and the expected sum s in currying syntax (a)(s). Returns a pair of matching integers as an array, or undefined if no such pair exists.
a=>s=>(r=a.find((b,i)=>a.some(c=>i--&&b+c==s)))&&[r,s-r]

Formatted and commented
a =>                      // given an array of integers (a)
  s => (                  // and an expected sum (s)
    r = a.find((b, i) =>  // look for b at position i in a such that:
      a.some(c =>         //   there exists another c in a:
        i-- &&            //     - at a different position
        b + c == s        //     - satisfying b + c == s
      )                   //   end of some()
    )                     // end of find(): assign the result to r
  ) &&                    // if it's not falsy:
  [r, s - r]              // return the pair of integers

Test

let f =

a=>s=>(r=a.find((b,i)=>a.some(c=>i--&&b+c==s)))&&[r,s-r]

console.log(f([1,7,4,6,5,3,8,2])(8))
console.log(f([1,2,3,4])(8))

Perl 5, 51 bytes
46 bytes of code + for 5 bytes for -pli flags.
$\="$_ $v"if$h{$v=$^I-$_};$h{$_}=1}{$\||exit 1

Try it online!
The idea is to iterate on the input list: on a number x ($_), if we previously saw n-x ($^I-$_) then we found what we were looking for, and set $\ to these two values ("$_ $v"). At the end, if $\ isn't set, then we exit 1, else it will be implicitly printed.

Does a literal tab work in place of the two characters ^I?

@ais523 It looks like I can't. Maybe it was possible on older versions of Perl though.

Röda, 60 56 bytes
f s,a{seq 1,s|{|x|[[x,s-x]]if[x in a,s-x in a-x]}_|pull}

Try it online!
This code throws an error if there is no answer. It generates all possible pairs that can form the sum s, ie. 1, s-1, 2, s-2, 3, s-3, ... Then it checks if both numbers are in the array a and if so, pushes them to the stream. pull reads one value from the stream and returns it. If there are no values in the stream, it throws an error. a-x returns the array a with x removed.

Jelly, 14 bytes
ŒcS=⁹$$ÐfḢṄo⁶H

Try it online!
This is a function (not a full program) that outputs to standard output. (The TIO link has a wrapper that runs a function and disregards its return value.)
This program could be 4 bytes shorter if not for the exit code requirement; returning an exit code of 1 in Jelly is fairly hard. (It's possible that there's a terser way to do this that I've missed.)
Explanation
ŒcS=⁹$$ÐfḢṄo⁶H
Œc                All pairs of values from {the first argument}
       Ðf         Take only those which
  S=⁹               sum to {the second argument}
     $$           Parse the preceding three builtins as a group
         Ḣ        Take the first result (0 if there are no results)

          Ṅ       Output this result (plus a newline) on standard output
           o⁶     If this value is falsey, replace it with a space character
             H    Halve every element of the value

We can halve every integer in a pair just fine, so the o⁶H will do nothing if we found a result, other than returning a useless return value that isn't relevant anyway (the Ṅ serves as a convenient single-byte method to determine the function's return value early, under PPCG rules). However, if we didn't find a result, we end up trying to halve a space character, an operation so meaningless it causes the Jelly interpreter to crash. Fortunately, this crash produces an exit code of 1.

Javascript, 114 96 86 84 bytes
a=>b=>{c=b.length;for(x=0;x<c;x++)for( y=x;++y<c;)if(b[x]+b[y]==a)return[b[x],b[y]]}

Saved 1 byte thanks to @Cyoce and another 8 bytes thanks to @ETHProductions
This returns a tuple with the first combination of list-elements that sum up to the given input, or nothing for no match. I've removed the vars in the function; REPL.it crashes without them, but the Chrome Dev Console handles this just fine...
Try it online!

Doesn't exit code 1, as the challenge specifically requests for invalid input. It's an invalid answer for now, but I've asked OP about this requirement for languages that can't do that easily.

@Matt Yes, that rule is observed: y=x+1 takes care of that.

You can use a=>b=>... to save a byte

You can save another three bytes with for(y=x;++y<b.length;){. Also, you can remove all sets of braces except the outermost one, and you can remove the space after return

Python 2, 60 bytes
This short, until rules with exiting with code 1 are clarified. Now exits with error if nothing is found.
-5 bytes thanks to @Peilonrayz
-4 bytes thanks to @Rod
Try it online
a,s=input()
while a:
 x=a.pop()
 if s-x in a:r=s-x,x
print r

@Peilonrayz Didn't realize that, thank you!

@Peilonrayz This would violate fith rule: two integers at different positions in list must be returned. (i.e. you can't return the same number from the same position twice)

You can use spaces+tabs for mixed indentation to reduce 2 bytes or switch to input()
to reduce 4 bytes

input() automatically delivers the right type of object, not only strings? That's cool.

@Eric Duminil Yeah. It's equivalent to eval(raw_input()) (I think).

PowerShell, 109 97 bytes
param($i,$a)($c=0..($a.count-1))|%{$c-ne($f=$_)|%{if($a[$f]+$a[$_]-eq$i){$a[$f,$_];exit}}};exit 1

Took a 12 byte deal that  AdmBorkBork offered
Explanation
# Get the parameter passed where $i is the addition target from the array of numbers in $a
param($i,$a)

($c=0..($a.count-1))|%{
    # We are going to have two loops to process the array elements.
    # The first loop element will be held by $f
    $f=$_
    # Create a second loop that will be the same as the first except for the position of $f to
    # prevent counting the same number twice.
    $c|?{$_-ne$f}|%{
        # Check if the number at the current array indexes add to the target value. If so print and exit.
        if($a[$f]+$a[$_]-eq$i){$a[$f],$a[$_];exit}
    }

}
# If nothing was found in the loop then we just exit with error.
exit 1

The current rules look for exit code which this does. Those could be removed and just check for numbers being returned and a falsy.
Sample Usage
If the code above was saved as function s
s 8 @(1,2,3,4)
s 8 @(1,7,4,6,5,3,8,2)

You can save a few more bytes by eliminating $c and looping downward -- ($a.count-1)..1|%{$f=$_;--$_..0|%{if...

C++ 133 bytes (compiled with clang 4 and gcc 5.3 -std=c++14)
#include <set>
auto f=[](auto s,int v,int&a,int&b){std::set<int>p;for(auto i:s)if(p.find(i)==end(p))p.insert(v-i);else{a=v-i;b=i;}};

C 108 bytes
void f(int*s,int*e,int v,int*a,int*b){do{int*n=s+1;do if(v-*s==*n){*a=*s;*b=*n;}while(++n<e);}while(++s<e);}

Welcome to the site! Unfortunately, I think you need to add 15 bytes for #include <set> and a few more for std::set. Although you can also save some bytes if you remove the braces around p.insert(v-i);

@DJMcMayhem  oh, thank you. So should i include main()?

@em2er No, you don't need to include main. We consider (unless stated otherwise in the challenge) that a function is a valid submission. (welcome on the site btw!)

No, a function submission is fine. (And much shorter because you can take the input as arguments) You just need to count any includes that your submission requires.

Also, I'm not sure about the end function. Should that be std::end or p.end?

@DJMcMayhem @Dada thanks a lot! i am not sure with end too, but it compiles on gcc without std:: (and set if course not)

Hmm. Well, as long as it compiles, I guess it's fine. I thought of a way you could save some bytes. If you took two extra arguments by reference, you could modify them and then you won't need to print them. Then you can remove the exit and #include <stdio.h>. This would give you #include <set> void f(auto s,int v,int&a,int&b){std::set<int>p;for(auto i:s)if(p.find(i)==end(p))p.insert(v-i);else{a=v-i;b=i;return;}} for 137

125 bytes and 83 bytes

Haskell, 34 bytes
(n:v)#s|elem(s-n)v=(n,s-n)|1<2=v#s

Try it online!
For each element of the list, this function checks if (sum-element) is in the following part of the list. Returns the first couple it finds. If the function reaches the end of the list it throws a "non -exhaustive patterns" error and exits with code 1.

I'm afraid this approach does not work for inputs like [2,2]#4.

@Laikoni Thank you, I hadn't read the challenge well enough. This new version should be correct (and shorter^^)

R, 49 bytes
function(x,y){r=combn(x,2);r[,colSums(r)==y][,1]}

This finds all 2-combinations of x and returns a matrix. Then, sums by column and finds all the sums that equal to y (so without the [,1] part at the end it will print all the combinations that their sums equal to y)

Japt, 9 bytes
Saved many bytes thanks to @ETHproductions
à2 æ_x ¥V

Try it online!
Explanation
à2 æ_x ¥V
à2         // Creates all combinations of the input, length 2
   æ       // Returns the first item where:
    _x     //     The sum of the two items in each set
       ¥V  //     == Second input

Example
Input:        [1,2,3], 4
à2         // [[1,2],[1,3],[2,3]]
   æ_x     // [3,    4,    5    ]
       ¥V  //  3!=4, 4==4 ✓
Output:    //  1,3

Clojure, 77 bytes
#(first(mapcat(fn[i a](for[b(drop(inc i)%):when(=(+ a b)%2)][a b]))(range)%))

Returns the first such pair or nil.

Haskell, 62 bytes
r=return;s#[]=r 1;s#(a:b)|elem(s-a)b=print(a,s-a)>>r 0|1<2=s#b

I still don't know what's allowed by the challenge and what not. I'm going for a function that prints a pair of numbers and returns 0 if there's a solution and prints nothing and returns 1 if there's no solution. As printing is I/O, I have to lift the return values into the IO-Monad (via return) and the actual type of the function is Num a => IO a.
Usage example (with return value printed by the repl):
*Main> 4 # [2,2]
(2,2)
0

Try it online!.
If raising exceptions is allowed, fail will save some bytes (total 51):
s#[]=fail"";s#(a:b)|elem(s-a)b=print(a,s-a)|1<2=s#b

Jelly, 9 bytes
ŒcS=¥ÐfḢZ

Jelly has no way of setting the exit code to arbitrary values, so this produces a TypeError for input without a valid solution that will cause the parent interpreter to exit with exit code 1.
Try it online!
How it works
ŒcS=¥ÐfḢZ  Main link. Argument: A (array of integers), n (integer)

Œc         Yield all 2-combinations of different elements of A.
     Ðf    Filter by the link to the left.
    ¥        Combine the two links to the left into a dyadic chain.
  S            Take the sum of the pair.
   =           Compare the result with n.
       Ḣ   Head; extract the first pair of the resulting array.
           This yields 0 if the array is empty.
        Z  Zip/transpose the result.
           This doesn't (visibly) alter pairs, but it raise a TypeError for 0.

Nova, 101 bytes
q(Int[] a,Int x)=>a{if(Int y=a.firstWhere({a.contains(x-a.remove(0))}))return [y,x-y];System.exit(1)}

One nice thing about code golf is that it helps me find bugs in my language. e.g. the space required between return and [y,x-y].
Once I add push/pop functions to Array.nova and fix return, would be 96 bytes:
q(Int[] a,Int x)=>a{if(Int y=a.firstWhere({a.contains(x-a.pop())}))return[y,x-y];System.exit(1)}

Usage:
class Test {
    static q(Int[] a,Int x)=>a{if(Int y=a.firstWhere({a.contains(x-a.remove(0))}))return [y,x-y];System.exit(1)}

    public static main(String[] args) {
        Console.log(q([1, 2, 3, 4, 5], 8)) // [5, 3]
        Console.log(q([1, 2, 3, 4, 5], 5)) // [1, 4]
        Console.log(q([1, 2, 3, 4], 8)) // exit code 1
    }
}

Edit:
Also, there's this way at 73 bytes (69 using pop), too:
q(Int[] a,Int x)=>[Int y=a.firstOrThrow({a.contains(x-a.remove(0))}),x-y]

firstOrThrow will throw an Exception, which will be uncaught and therefore ultimately exiting the program with exit code 1. ;)
This way seems more readable too.

Pyth, 12 bytes
hfqsThQ.ceQ2

Explanation
       .ceQ2   Get all pairs from the second input
 fqsThQ        Find the ones whose sum is the first input
h              Take the first (exits with error code 1 if there aren't any)

PHP, 88 bytes
for($i=1;$a=$argv[$k=++$i];)for(;$b=$argv[++$k];)if($a+$b==$argv[1])die("$a $b");die(1);

takes input from command line arguments, sum first. Run with -nr.
Fortunately, die/ exit exits with 0 when you give it a string as parameter.
I tried to merge the loops to one; but it requires a longer initialization and test this time.

Bad day? for($i=1;$a=$argv[$k=++$i];)for(;$b=$argv[++$k];)$a+$b!=$argv[1]?:die(!0); and you should have a look on this https://codegolf.stackexchange.com/questions/120803/does-the-sum-of-2-numbers-in-the-list-equal-the-desired-sum/120828#120828

Mathematica, 76 bytes
f::e="1";If[(l=Cases[#~Subsets~{2},x_/;Tr@x==#2])=={},Message@f::e,First@l]&

Fairly straightforward: #~Subsets~{2} gets all 2-element subsets of the list, then Cases[...,x_/;Tr@x==#2] picks only the ones whose sum is the number we want. If there are none of these, If[l=={}, Message@f::e,First@l] prints the error message f::e : 1 that we defined earlier (since I have no idea what else "exit status 1" might mean for Mathematica); otherwise, it returns the first entry in the list of pairs that sum to the correct thing.
If we're allowed to return a falsey value instead of doing that weird exit status thing, the following code has 58 bytes:
If[(l=Cases[#~Subsets~{2},x_/;Tr@x==#2])=={},1<0,First@l]&

Scala, 55 41 bytes
(l,n)=>l combinations 2 find(_.sum==n)get

Returns a list of the two numbers if they exist and throws an error otherwise. Uncaught, this error will result in an exit status of 1.

Ruby, 53 48 bytes
->a,s{p(a.combination(2).find{|x,y|x+y==s})?0:1}

Input: a is the list, s is the expected sum.
If the 2 numbers are found, print them and return 0, otherwise return 1, as in the specification.

TI-Basic, 59 bytes
Prompt L1
Prompt X
While 1
L1(1→B
seq(L1(C),C,2,dim(L1→L1
If sum(not(X-L1-B
Then
Disp B,X-B
Return
End
End

Explanation:
Prompt L1               # 4 bytes, input array like "{1, 2, 3}"
Prompt X                # 3 bytes, Input target sum
While 1                 # 3 bytes, until the list is empty
L1(1→B                  # 7 bytes, try the first element (now B)
seq(L1(C),C,2,dim(L1→L1  # 18 bytes, remove first element from list
If sum(not(X-L1-B       # 10 bytes, if any element in the list plus B is the target
Then                    # 2 bytes, then...
Disp B,X-B              # 7 bytes, print it and it's "complement"
Return                  # 2 bytes, and exit gracefully
End                     # 2 bytes
End                     # 1 byte
If the program did not exit gracefully, it will cause an error when there are not enough elements in the list for it to continue.

CJam, 23 bytes
l~_,1>{e!2f<::+#)}{;;}?

Input is sum numbers. For example: 6 [3 2 3]. Leaves a positive number for truthy and an empty string or 0 for falsey.
Explanation:
l~    e# Read input and evaluate:  | 7 [3 2 3]
_     e# Duplicate:                | 7 [3 2 3] [3 2 3]
,     e# Take the length:          | 7 [3 2 3] 3
1>{   e# If more than 1:           | 7 [3 2 3]
  e!  e#   Unique permutations:    | 7 [[2 3 3] [3 2 3] [3 3 2]]
  2f< e#   Slice each to length 2: | 7 [[2 3] [3 2] [3 3]]
  ::+ e#   Some each:              | 7 [5 5 6]
  #   e#   Index:                  | -1
  )   e#   Increment:              | 0
}{    e# Else:                     | 7 [3 2 3]
  ;   e#   Pop                     | 7
  ;   e#   pop                     |
}?    e# Endif
e# Implicit output: 0


text:
Shortest code that throws SIGBUS
We've had challenges for SIGSEGV and SIGILL so why not...
Write the shortest code that results in a Bus Error (SIGBUS) in any programming language.
Your program can't call raise() or kill(getpid(),sig) or pthread_kill(pthread_self(),sig), or any other equivalent.

@ГригорийПерельман It's not a duplicate, no answer for that challenge can be applied to this one without nontrivial modification.

@orlp There are Bash, Python, Perl, and C answers that are all essentially raise(11). They can be trivially modified to be raise(7) instead for this challenge.

Are you riding the SIGBUS, or driving it?

Java/Groovy is also just System.exit(#); where you only change the # to throw a different exit code... This is a very trivial difference in many languages.

@mbomb007 neither. You're throwing it. That seems like the most difficult of the three.

Voting to reopen because the rule "Your program can't call raise() or kill(getpid(),sig) or pthread_kill(pthread_self(),sig), or any other equivalent." bans those copy-paste answers.

@pppery While that rule may make this not a duplicate it does make this unclear.

x86_64 bytecode, 15 bytes
   0:   c7 04 24 00 00 04 00    movl   $0x40000,(%rsp)
   7:   9d                      popfq
   8:   8b 04 25 01 00 00 00    mov    0x1,%eax

Turns on the misaligned address trap flag and then immediately triggers it.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Visualize nested array
You will be given a nested array. Your program has to visualize the array.

But.. How?
For example, let's assume we have a nested array, like [["1","2"],[["1","2"],"3"],"4",[[[["5"]]]],"6"].
This nested array can be visualised as:
->1
->2
-->1
-->2
->3
>4
---->5
>6

Examples
Input 1:
["Atom",["Proton",["Up Quark", "Up Quark", "Down Quark"], "Neutron", ["Up Quark", "Down Quark", "Down Quark"], "Electron"]]
Output 1:
>Atom
->Proton
-->Up Quark
-->Up Quark
-->Down Quark
->Neutron
-->Up Quark
-->Down Quark
-->Down Quark
->Electron

Input 2:
[["1","2"],["3","4"]]
Output 2:
->1
->2
->3
->4

Rules

You may use string (or other types which work like a nested array) as input.
The maximum level of "layers" is 2^32-1.

Does it have to have this exact visualisation?

@mnbvc Yes, unless I force to do it people start to twist the I/O a lot. Believe me, I tried it.

I feel like retina will win this.

Are there any restrictions on what characters can appear in the strings?

Additional related questions 1, 2

Do we have to handle inconsistent separators? If yes, will whitespace characters occur only after the comma? Will there be only 0 or 1 whitespace or can be even more?

APL, 32 bytes
{1=≡⍺:⎕←⍺,⍨⍵↑1↓⍵/'->'⋄⍺∇¨⍵+1}∘0

Test:
      r
┌────┬─────────────────────────────────────────────────────────────────────────────────────────┐
│Atom│┌──────┬──────────────────────────────┬───────┬────────────────────────────────┬────────┐│
│    ││Proton│┌────────┬────────┬──────────┐│Neutron│┌────────┬──────────┬──────────┐│Electron││
│    ││      ││Up Quark│Up Quark│Down Quark││       ││Up Quark│Down Quark│Down Quark││        ││
│    ││      │└────────┴────────┴──────────┘│       │└────────┴──────────┴──────────┘│        ││
│    │└──────┴──────────────────────────────┴───────┴────────────────────────────────┴────────┘│
└────┴─────────────────────────────────────────────────────────────────────────────────────────┘
      {1=≡⍺:⎕←⍺,⍨⍵↑1↓⍵/'->'⋄⍺∇¨⍵+1}∘0 ⊢ r
>Atom
->Proton
-->Up Quark
-->Up Quark
-->Down Quark
->Neutron
-->Up Quark
-->Down Quark
-->Down Quark
->Electron

Explanation:

{...}∘0: run the following function with 0 bound to ⍵:

1=≡⍺:: if the input has depth 1 (i.e. an array that does not contain other arrays):

⍵/'->': create a string containing ⍵ -s and ⍵ >s,
1↓: drop the first element,
⍵↑: and take the first ⍵ elements. This results in a string containing ⍵-1 dashes and one >.
⍺,⍨: append the input to it,
⎕←: and output that to the screen

⋄: otherwise,

⍺∇¨⍵+1: add 1 to ⍵ and apply the function to each nested array

Wait, does it take input in that ascii-art form?

@Riker: No, it takes a normal nested array, however this is how Dyalog APL displays a nested array, and (I thought) it makes it obvious what is going on. You could construct it by writing e.g. ('Atom' ('Proton' ('Up Quark' 'Up Quark' 'Down Quark') 'Neutron' ('Up Quark' 'Down Quark' 'Down Quark') 'Electron')).

Ah, okay. That clears it up. Somewhat dissapointed now though....

Try it online!

Mathematica, 58 57 56 bytes
Thanks to Greg Martin for saving 1 byte.
Thanks to ngenisis for saving 1 byte.
MapIndexed[Print[Table["-",Tr[1^#2]-1]<>">",#]&,#,{-1}]&

Welcome to PPCG! You should know that answers that provide little or no explanation get automatically flagged by the system and end up in the Low Quality Review Queue. That might get your answer deleted. Note that if you have several deleted answers you might get a temporary suspension. Just a little heads up!

@StewieGriffin Thanks for the warm welcome, I'll keep that in mind!

@StewieGriffin are you welcoming a sitemod? What is going on here? Is this an inner joke? #confused And good spring for you guys if you are on the north.

@Mindwin: Stack Exchange has a filter designed to catch answers that are unlikely to be helpful. This sort of post (title + short code sample, no commentary) is highly likely to cause false positives on it, because it looks a lot like a low effort post to a computer (and Stewie Griffin's comment contains a link to a screenshot that indicates that a false positive did in fact happen; it's making fun of the situation). Here's an example of another post that got caught in the filter.

When I run this, the final <> appears in the printout; but replacing it with , fixed it.

@GregMartin I assume that the input is a list of strings, not numbers (as in the challenge). That's a nice byte-saving, though. :)

Win-win situation! :)

But I´d really love some explanation from You every now and then, so I can get to know Mathematica (and the other cryptic stuff You´re doing) a little.

You can save one byte by using Table instead of Array and changing "-"& to "-"

@ngenisis Oh right, I forgot that Table works without a list parameter now. Will change in a bit.

@Titus I'd love to add one but I don't want to invalidate Stewie's comment. :(

Java 7, 153 141 114 bytes
String r="";<T,S>S c(S s,T o){for(T x:(T[])o)if(x instanceof Object[])c("-"+s,x);else r+=s+">"+x+"\n";return(S)r;}

-39 bytes thanks to @Barteks2x
Explanation:
String r="";                         // Result String outside the method / on class-level
<T,S> S c(S s, T o){                 // Recursive Method with generic String and Object parameters and String return-type
  for(T x : (T[])o)                  //  Loop over the input-array
    if(x instanceof Object[])        //   If the current item is an array itself:
      c("-"+s, x);                   //    Recursive method-call with this array
    else                             //   Else:
      r += s+">"+x+"\n";             //    Append return-String with stripes String-input, ">", current item, and a new-line
                                     //  End of loop (implicit / single-line body)
  return (S)r;                       //  Return the result-String
}                                    // End of method

Test code:
Try it here.
class M{
  String r="";<T,S>S c(S s,T o){for(T x:(T[])o)if(x instanceof Object[])c("-"+s,x);else r+=s+">"+x+"\n";return(S)r;}

  public static void main(String[] a){
    M m = new M();
    System.out.println(m.c("", new Object[]{new Object[]{1,2},new Object[]{new Object[]{1,2},3},4,new Object[]{new Object[]{new Object[]{new Object[]{5}}}},6}));
    m.r = "";
    System.out.println(m.c("", new Object[]{"Atom",new Object[]{"Proton",new Object[]{"Up Quark","Up Quark","Down Quark"}},new Object[]{"Neutron",new Object[]{"Up Quark","Up Quark","Down Quark"}},"Electron"}));
  }
}

Output:
->1
->2
-->1
-->2
->3
>4
---->5
>6

>Atom
->Proton
-->Up Quark
-->Up Quark
-->Down Quark
->Neutron
-->Up Quark
-->Up Quark
-->Down Quark
>Electron

You can get it slightly shorter (143 or even 142) by using ternary operator in for(int j=i;j-->0;r+="-"); to also do what the next line does, and using generic argument instead of Object[]:
String r="";<T>String c(int i,T[] o){for(T x:o)if(x instanceof Object[])c(i+1,(T[])x);else for(int j=i;j-->=0;r+=j<0?">"+x+"\n":"-");return r;}
And even 1 character less if passing 1 instead of 0 as the first argument is ok.

I found a way to make it even shorter by removing the [] from generic argument, it saves additional 2 characters (but can't edit the comment after >5 minutes)

@Barteks2x Thanks! -12 bytes thanks to you. :) Btw, removing the [] from the parameter to save 1 additional byte gives an error. See the error here at >Debug after running.

String r="";<T>String c(int i,T a){for(T x:(T[])a)if(x instanceof Object[])c(i+1,x);else for(int j=i;j-->0;r+=j<1?">"+x+"\n":"-");return r;} this works. Also you can do similar generic trick with string to save additiona  byte but requires either storing the result in variable before printing it, or an explicit cast (ambigous method call): String r="";<T,S>S c(int i,T a){for(T x:(T[])a)if(x instanceof Object[])c(i+1,x);else for(int j=i;j-->0;r+=j<1?">"+x+"\n":"-");return(S)r;}

I'm not sure if this is considered allowed, but 114 bytes here, with empty string as argument instead of zero (can be 1 character less if ">" is allowed as argument)
String r="";<T,S>S c(S p,T a){for(T x:(T[])a)if(x instanceof Object[])c("-"+p,x);else r+=p+">"+x+"\n";return(S)r;} And the requirement for string cast on return type when calling it is gone.

PHP, 77 74 73 bytes
4 bytes saved thanks @manatwork.
function f($a,$p=">"){foreach($a as$e)"$e"!=$e?f($e,"-$p"):print"$p$e
";}

recursive function, requires PHP 7.1 or newer for the negative string index.
"$e" is Array for arrays; so "$e"!=$e is the same as is_array($e).

start with prefix >
prepend a - to the prefix for each level
print prefix+element+newline for atoms

75 bytes: function f($a,$p=""){foreach($a as$e)echo$p,is_array($e)?f($e,"-"):">$e\n";}

@IsmaelMiguel Nice idea; but it fails if the sub-array has more than one element.

@Titus PHP recursion anyway fails to meet the second rule of 2^32-1 levels :P

@Christoph not in PHP, if you don´t cripple your server. But ... possibly in the default config? Have to check!

@Titus at least it hits the default memory limit pretty fast.

@Titus I think I found the relevant code here: It allocates a new node on a doubly linked list based stack for each call. So recursion is indeed not the problem for PHP but the memory limit is.

if it werent for the required formatting, print_r($array) would be even smaller :)

@Christoph Check out my iterative solution; I got it down to 93 bytes now.

Did just a quick test, but seems that is_array($e) could be replaced with $e[-1]!=="".

@manatwork That´s PHP<7.1 ... in PHP 7.1, it can be done with $e[-]=="" ... and with the condition reversed $e[-1]>"". Nice find!

Maybe I miss some corner cases, but for now looks like $e[-1]>"" can be replaced with "$e"==$e. At least in the ancient PHP 5.6 I use.

@manatwork This should even work in PHP 3; and it still does in 7.1.

why print and not echo

@ArtisticPhoenix because echo cannot be used as an expression

C99 (GCC), 201 187 140 112 109
f(char*a){for(long d=1,j;j=d+=*++a>90?92-*a:0;)if(*a<35){for(;j||*++a^34;)putchar(j?"->"[!--j]:*a);puts("");}}

expanded form:
f(char*a){
    for(long d=1,j;j=d+=*++a>90?92-*a:0;)
        if(*a<35){
            for(;j||*++a^34;)putchar(j?--j?45:62:*a);
            puts("");
        }
}

This takes a string in the correct format and terminates when finding the last matching ].
It doesn't use recursion and uses long types to actually achieve the second rule: 2^32-1 levels. Most scripting languages have a limited recursion depth or simply crash on stack overflow.
I'm not used to golf in C any help is appreciated :)
Thanks at bolov for his tips !
Specially thanks to Titus who's always up for a good round of golfing (even in C) !
Another two bytes saved by the fact that we can finish once we match the last ] and don't need to match a null char.
It can be tested at Wandbox.

Let us continue this discussion in chat.

Could you not shorten the second line to for(int d=1 ...? long has 4 characters while int only has 3, and there is no reason that you need to make it go above the 2^32 - 1 for your submission to be valid, saving you a single byte.

@Restioson int is signed and therefore only works until 2^31-1.

@Christoph the challenge stated that you did not have to go any further than that.

@Restioson The challenge states as rule The maximum level of "layers" is 2^32-1.. 2^31-1 is a lot less than 2^32-1. 2^32-1 doesn't fit an int while it fits an unsigned or long (that is on most systems/compilers of course). Therefore int wouldn't make a correct answer (like most answers here fail to be).

Python 2, 65 64 bytes
f=lambda o,d=0:o<''and'\n'.join(f(e,d+1)for e in o)or'-'*d+'>'+o

Right now my answer consistently starts with no dashes, so ["foo", "bar"] is:
>foo
>bar

import sys, pprint; pprint.pprint(sys.argv) is 43 bytes but I do not know if it breaks code golf rules.

This saves one byte: f=lambda o,d=0:o<''and'\n'.join(f(e,d+1)for e in o)or'-'*d+'>'+o

@Carel can't you do 'import pprint as p' or maybe (not sure if this works) 'import pprint.pprint as p' (goodness I can't seem to find the back tick on my phone keyboard)

@Cole Hmm.. import sys, pprint.pprint as p; p(sys.argv) is still 43 but a good suggestion none the less ;D Trying import sys.argv as v actually lengthens it somewhat ~48 bytes. If one could eliminate sys.argv they'd save alot but the program becomes quite useless then. A recursive approach is quite long, def p(L,d=0): [p(i,d+1) if isinstance(i,list) else print(">"*d + i) for i in L], ~80 bytes.

JavaScript (ES6), 58 51 bytes
f=(a,s='>')=>a.map(e=>e.map?f(e,'-'+s):s+e).join`
`

Edit: Saved 7 bytes when @Arnauld pointed out that I could combine my two approaches.

PHP, 129 123 112 109 95 93 91 bytes
for(;a&$c=$argn[++$i];)$c<A?$c<"-"?a&$s?$s=!print"$p>$s
":0:$s.=$c:$p=substr("---$p",$c^i);

iterative solution takes string from STDIN:
Run with echo '<input>' | php -nR '<code>' or test it online.
breakdown
for(;a&$c=$argn[++$i];)     // loop $c through input characters
    $c<A                        // not brackets?
        ?$c<"-"                     // comma or quote?
            ?a&$s?$s=!print"$p>$s\n":0  // if $s not empty, print and clear $s
            :$s.=$c                     // digit: append to $s
        :$p=substr("---$p",$c^i)    // prefix plus or minus one "-"
;

Happy that the numbers are in quotes; so I only need one action at a time.
ASCII fiddling
char    ascii   binary/comment
 "       34
 ,       44
 [       91     0101 1011
 ]       93     0101 1101

 A       65     $c<A    true for comma, quote and digits
 -       45     $c<"-"  true for comma and quote

                =0011 1010 -> 50 -> "2"
i^"["   105^91  ^0101 1011
 i      105      0110 1001
i^"]"   105^93  ^0101 1101
                =0011 0100 -> 52 -> "4"

Adding 3 dashes to $p and removing 2 for [, 4 for ] adds one for [ and removes one for ].

Good job again!

Ruby, 49 45 46 bytes
f=->c,p=?>{c.map{|x|x==[*x]?f[x,?-+p]:p+x}*$/}

Example:
puts f[["Atom",["Proton",["Up Quark", "Up Quark", "Down Quark"], "Neutron", ["Up Quark", "Down Quark", "Down Quark"], "Electron"]]]

>Atom
->Proton
-->Up Quark
-->Up Quark
-->Down Quark
->Neutron
-->Up Quark
-->Down Quark
-->Down Quark
->Electron

Explanation:
Recursive function: if x==[*x] then x is an array, and we iterate over it. If not, indent it.

Perl 5, 55 bytes
53 bytes of code + -nl flags.
/"/?print"-"x~-$v.">$_":/]/?$v--:$v++for/]|\[|".*?"/g

Try it online!
Not optimal for regex because of some edgy cases that could potentially occur (in particular, if an element of the array contains brackets inside).
A recursive anonymous function would be barely longer though (61 bytes):
sub f{my$v=pop;map{ref?f(@$_,$v+1):"-"x$v.">$_"}@_}sub{f@_,0}

Try it online!
But the way Perl deals with parameters isn't optimal for golfing functions: no optional parameters means I have to do a second function (anonymous) calling the first one, and I have to explicitly get the last parameter with that long my$v=pop.

Haskell, 104 bytes
l@(x:y)#(a:m)|[(h,t)]<-reads$a:m=y++h++l#t|a<'#'=l#m|a<'-'='\n':l#m|a>'['=y#m|q<-'-':l=q#m
l#_=""
(">"#)

Haskell doesn't have nested lists with different depths, so I have to parse the input string on my own. Luckily the library function reads can parse Strings (i.e. "-enclosed char sequence), so I have a little help here.
Usage example:
*Main> putStrLn $ (">"#) "[[\"1\",\"2\"],[\"3\",\"4\"]]"
->1
->2
->3
->4

Try it online!.
How it works:
The function # goes through the string char by char and keeps the nesting level (the first parameter l) as a string of - with a final >. If the head of the list can be parsed as a String, take l and the String followed by recursive call with the String removed. If the first char is a Space, skip it. If it's a ,, take a newline and go on, if it's ], lower the nesting level and go on and else (only [ left) raise the nesting level and go on. Recursion ends with the empty input string. The main function (">"#) sets the nesting level to ">" and calls #.

SWI-Prolog, 115 bytes
p(L):-p(L,[>]).
p([],_):-!.
p([H|T],F):-p(H,[-|F]),p(T,F),!.
p(E,[_|F]):-w(F),w([E]),nl.
w([]).
w([H|T]):-write(H),w(T).

Line breaks added for readability only, not included in byte count.
p predicate recursively traverses the arrays, adding a '-' to the prefix F when moving a level deeper. w is used to write the prefix array as well as the actual element to the output.
Example:
?- p(["Atom",["Proton",["Up Quark", "Up Quark", "Down Quark"], "Neutron", ["Up Quark", "Down Quark", "Down Quark"], "Electron"]]).
>Atom
->Proton
-->Up Quark
-->Up Quark
-->Down Quark
->Neutron
-->Up Quark
-->Down Quark
-->Down Quark
->Electron

Batch, 249 bytes
@echo off
set/ps=
set i=
:t
set t=
:l
set c=%s:~,1%
set s=%s:~1%
if "%c%"=="[" set i=-%i%&goto l
if not "%c%"=="]" if not "%c%"=="," set t=%t%%c%&goto l
if not "%t%"=="" echo %i:~1%^>%t%
if "%c%"=="]" set i=%i:~1%
if not "%s%"=="" goto t

Annoyingly Batch has trouble comparing commas. Sample run:
[Atom,[Proton,[Up Quark,Up Quark,Down Quark],Neutron,[Up Quark,Down Quark,Down Quark],Electron]]
>Atom
->Proton
-->Up Quark
-->Up Quark
-->Down Quark
->Neutron
-->Up Quark
-->Down Quark
-->Down Quark
->Electron

Retina, 63 54 52 bytes
Saved 2 bytes thanks to Martin Ender
.*?".*?"
$`$&¶
T`[] -~`-]_`.(?=.*".*")
-]

-"
>
T`]"

Try it online!
Explanation
.*?".*?"
$`$&¶

First, the array is broken up by replacing each quoted string with everything that came before it, plus itself, plus a newline. By breaking it up like this, it's possible to find the unmatched opening brackets before each string.
T`[] -~`-]_`.(?=.*".*")

This transliteration will replace [ with -, leave ] unchanged, and delete every other character ( -~ is all printable ASCII). However, it only replaces characters appearing before the final string on each line.
-]

Next all instances of -] are removed. These correspond to matching bracket pairs, and we only want unmatched brackets. After these are removed, each line has a number of -s equal to how many unmatched opening brackets came before it.
-"
>

The last - before a " is replaced with >, to form the arrows.
T`]"

Finally, all remaining ]s and "s are deleted.

This looks like it assumes that there won't be (escaped) quotes inside the strings. I'm not sure whether that's legitimate but I've asked for clarification.

@MartinEnder Good catch, I'll keep an eye on it

Röda, 54 bytes
f d=""{{|n|{n|f d=`$d-`}if[n is list]else[`$d>$n
`]}_}

Try it online!
It's a function that reads the input array from the stream. For each item, it either calls itself recursively or prints the item.

Python 3, 80 Bytes
Python's lambdas support recursion it seems, who knew ?
p=lambda l,d=1:[p(i,d+1)if isinstance(i,list)else print("-"*d+">"+i)for i in l]

This is a counter/compliment to orlp's answer.

Welcome to PPCG! It seems you've counted a trailing linefeed or something (because I only count 80 bytes) and you don't need the spaces around the =. I also suspect you can drop all the spaces after the three ), but I'm not very familiar with golfing in Python.

Groovy, 92 bytes
x={a,b->if(a instanceof List){a.each{x(it,b+1)}}else{y(a,b)}};y={a,b->println("-"*b+">$a")};

Stacked, 27 bytes
[@.1-'-'*\'>'\,,out]deepmap

Try it online!
Takes input from the top of the stack and leaves output on STDOUT. This is simple as doing a depth map, repeating - d times, concatenating with '>' and the element itself.

jq, 70 67 characters
(67 64 characters code + 3 characters command line option)
def f(i):if type=="array"then.[]|f("-"+i)else i+. end;.[]|f(">")

Sample run:
bash-4.3$ jq -r 'def f(i):if type=="array"then.[]|f("-"+i)else i+. end;.[]|f(">")' <<< '[["1","2"],[["1","2"],"3"],"4",[[[["5"]]]],"6"]'
->1
->2
-->1
-->2
->3
>4
---->5
>6

On-line test

Gema, 63 characters
\A=@set{i;-1}
[=@incr{i}
]=@decr{i}
"*"=@repeat{$i;-}>*\n
,<s>=

Like the other parsing solutions, assumes there will be no escaped double quotes in the strings.
Sample run:
bash-4.3$ gema '\A=@set{i;-1};[=@incr{i};]=@decr{i};"*"=@repeat{$i;-}>*\n;,<s>=' <<< '[["1","2"],[["1","2"],"3"],"4",[[[["5"]]]],"6"]'
->1
->2
-->1
-->2
->3
>4
---->5
>6

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/