Sum of Numbers of Array Given an array (N) of integers, check if it is possible to obtain a sum of S, by choosing some (or none) elements of the array and adding them.

Example #1

{1,2,3}
4


should output

1 (or true)


because 1 and 3 can be added to produce 4.

Example #2

{3,6,2}
0


should output

1 (or true)


because adding none of them together produces 0.

Example #3

{0,4,3,8,1}
6


should output

0 (or false)


because no combination of the elements in the array can be added to produce 6.


Example #4

{3, 2 ,0 ,7 ,-1}
8


should output

1 


because 2+7+(-1)=8
Mathematica

This is easy in Mathematica. (1) Generate the subsets of your input list, using the Subsets[] command (I had originally used Permutations[], which works but produces redundant results), (2) sum the numbers in each subset by mapping the Total[] command across the list of subsets, then (3) check to see if the target sum S is represented among those sums with MemberQ[]. To be concise, I've shown this below implemented as a single nested command.

Put your inputs in the first line and execute this:

list = {0, 4, 3, 8, 1}; target = 6;
MemberQ[Total /@ Subsets[list], target]


Assuming one-character variable names, that's 28 bytes of code.