2

I have a set of numbers, let's say: a=16 b=19 c=19 d=31 e=5 f=... etc.

How to create a simple function that shows how many combinations of the letters add up to at least the number n?

I have no clue what Mathematica Functions I should use to get started. Any help would be appreciated.

GambitSquared
  • 2,311
  • 15
  • 23

2 Answers2

5

n=80

number of subsets

Length@Select[Total /@ Subsets[{13, 15, 19, 19, 23, 31}], # >= 80 &]

and if you want to see the selected subsets type

Select[Subsets[{13, 15, 19, 19, 23, 31}], Total[#] >= 80 &]
ZaMoC
  • 6,697
  • 11
  • 31
0

First create a list of your allowable component integers:

myset = {1, 2, 3, 5, 20};

Then:

Length[Select[IntegerPartitions[20], ContainsOnly[myset]]]

(* 92 *)

IntegerPartitions gives a list of all the says you can add integers to give the candidate number. Select from all those possible lists the ones that contain only the elements in your allowable component integers using ContainsOnly (version 10). Then count (Length) that list.

If you must, you can kludge a function using set operations to select lists whose union with myset is myset.

David G. Stork
  • 41,180
  • 3
  • 34
  • 96