Skip to main content
added a commented version
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 60 bytes

f=(b,...a)=>eval(b.join`+`)?f(...a,b.slice(1),b.pop()?b:b):b

Try it online!

Commented

f = (                 // f is a recursive function taking:
  b,                  //   b[] = next array
  ...a                //   a[] = list of all other arrays
) =>                  //
  eval(b.join`+`) ?   // if the sum of b[] is not zero:
    f(                //   do a recursive call:
      ...a,           //     first try with the other arrays that were
                      //     already passed to this iteration
      b.slice(1),     //     then try with b[] without the leading term
      b.pop() ? b : b //     and finally with b[] without the trailing term
                      //     NB: we don't mind modifying b[] at this point,
                      //         and this is shorter than b.slice(0, -1)
    )                 //   end of recursive call
  :                   // else:
    b                 //   success: return b[]

JavaScript (ES6), 60 bytes

f=(b,...a)=>eval(b.join`+`)?f(...a,b.slice(1),b.pop()?b:b):b

Try it online!

JavaScript (ES6), 60 bytes

f=(b,...a)=>eval(b.join`+`)?f(...a,b.slice(1),b.pop()?b:b):b

Try it online!

Commented

f = (                 // f is a recursive function taking:
  b,                  //   b[] = next array
  ...a                //   a[] = list of all other arrays
) =>                  //
  eval(b.join`+`) ?   // if the sum of b[] is not zero:
    f(                //   do a recursive call:
      ...a,           //     first try with the other arrays that were
                      //     already passed to this iteration
      b.slice(1),     //     then try with b[] without the leading term
      b.pop() ? b : b //     and finally with b[] without the trailing term
                      //     NB: we don't mind modifying b[] at this point,
                      //         and this is shorter than b.slice(0, -1)
    )                 //   end of recursive call
  :                   // else:
    b                 //   success: return b[]
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 60 bytes

f=(b,...a)=>eval(b.join`+`)?f(...a,b.slice(1),b.pop()?b:b):b

Try it online!