Given an array of integers a which contains n integers, and a single integer x; remove the fewest amount of elements from a to make the sum of a equal to x. If no combinations of a can form x, return a falsy value.

As pointed out in a comment this is the maximum set with a sum of x, excuse my lesser math brain. I forgot a lot of terms since college.

\$\begingroup\$"Any value can be used as a falsy indicator, other than an array of integers." Does that include an empty array?\$\endgroup\$
– ShaggyNov 1 '18 at 0:09

\$\begingroup\$@shaggy [] is indicative of a potential truthy value, right? Is allowing that meta rule more important than distinct truthy and falsy?\$\endgroup\$
– Magic Octopus UrnNov 1 '18 at 13:31

\$\begingroup\$@JohnathanAllan if that error cannot be raised in a Truthy scenario- I'd suppose. But I feel this is intentionally attempting to stretch the spec. If i change the wording from indicator to return value is it fine then?\$\endgroup\$
– Magic Octopus UrnNov 1 '18 at 13:33

\$\begingroup\$I do believe consistent exit values do count as a return value though per meta?\$\endgroup\$
– Magic Octopus UrnNov 1 '18 at 13:59

8-byter (Try it!) – Outputs only one possible solution. For unsolvable inputs, it doesn't print anything to STDOUT, which is an empty string, which is technically speaking falsey in Pyth, but writes to STDERR. Thanks to FryAmTheEggman for suggesting this (ignoring STDERR and focusing on the STDOUT output only), thus saving 1 byte.

10-byter (Try it!) – For a clearer output, without using the singleton-list rule and using 0 rather than [] as a falsy value.

e+0fqz`sTy

Explanation

First, the code computes the powerset of the input list (all possible ordered sub-collections thereof). Then, it only keeps those collections whose sum is equal to the input number. It should be noted that the collections are generated from the shortest to the longest, so we focus on the last one. To obtain it:

The 8-byter simply uses the end built-in, which throws an error, but STDERR can be ignored as per our site rules, the output to STDOUT being an empty string, which is falsy.

The 9-byter takes the last element, but using the equivalent Python code lst[-1:] in place of lst[-1] to avoid errors from being thrown for unsolvable inputs.

The 10-byter prepends a 0 to the list of filtered sub-collections, then takes the end of that collection (last element). If the inputs aren't solvable, then 0 is naturally used instead.

\$\begingroup\$Wait, is the ; even necessary?\$\endgroup\$
– Jo KingNov 4 '18 at 10:40

\$\begingroup\$@JoKing It was necessary in an earlier iteration to avoid a "malformed double closure" error. But for some reason it can be omitted now. (I think after I replaced $^x with $_.)\$\endgroup\$
– nwellnhofNov 4 '18 at 12:04

\$\begingroup\$Remember that this is [code-golf] so you should try to make your byte count as small as possible! You have a leading newline and some other trivial whitespace golfs, and I bet someone else who knows python can golf this down further.\$\endgroup\$
– GiuseppeOct 31 '18 at 19:47

\$\begingroup\$@Giuseppe Thanks for reminding me of the leading whitespace. I spent some time trying to consolidate some parts of this, but decided to post it in the meantime in case any others can suggest edits.\$\endgroup\$
– GigaflopOct 31 '18 at 19:52

\$\begingroup\$Not a problem! It's been like 5 years since I did any Python, but doesn't range(x) generate (0...x-1)? So your range(len(a)) isn't giving you the possibility of leaving the array unchanged?\$\endgroup\$
– GiuseppeOct 31 '18 at 20:02

\$\begingroup\$@Giuseppe Eureka, that did it. I may have been focusing too much on the new material I was working with.\$\endgroup\$
– GigaflopOct 31 '18 at 20:06

\$\begingroup\$Instead of if a==[] and x==0 use if sum(a)==x. Then you can also remove +1 from range.\$\endgroup\$
– Vedant KandoiNov 1 '18 at 6:24

Just about equivalent to Fatalize's h⊇.+~t?∧, except a lot shorter, thanks to the predicate composition feature which according to the edit history of the reference was a work in progress until January 8, postdating the answer by over two months. ⟨⊇+⟩ is a sandwich, expanding to {[I,J]∧I⊇.+J∧}, where the braces are in this case irrelevant as the sandwich is on its own line anyhow.

The input
[I,J] is a list of two elements I and J.
. The output,
+J which sums to J
∧ (which we don't unify with the output),
I⊇ is a sublist of I
∧ (which we don't unify with [I,J]).

A far less dramatic transformation of Fatalize's answer, which uses the same predicates with the same variables but comes out a byte shorter from being organized differently:

Your Answer

If this is an answer to a challenge…

…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.

…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.

…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.

More generally…

…Please make sure to answer the question and provide sufficient detail.

…Avoid asking for help, clarification or responding to other answers (use comments instead).