Skip to main content
1 of 4
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES6), 119 bytes

Takes input as (array)(n). Returns either an array or false.

a=>n=>a.reduce(m=(a,x)=>[...a,...a.map(y=>(b=[...y,x],eval(b.join`+`)-n|m>(l=b.length)?b:(m=l,r=b)))],[[]],r=!n&&[])&&r

Try it online!

Arnauld
  • 197.7k
  • 20
  • 179
  • 650