Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This sounds like homework (if it is, please tag it as such), so I'll only give a few hints:</p> <ol> <li><code>HashSet</code> should do the job. However, note that in order for <code>HashSet</code> to work like a mathematical set (i.e. it cannot contain multiple occurrences of the same element), the element type (in this case, <code>Set&lt;Integer&gt;</code>) must have <code>equals()</code> and <code>hashCode()</code> implementations that tell the <code>HashSet</code> when two elements are equal. Most <code>Set</code> implementations do not have these methods implemented the way you'd expect, but you probably don't need it here. Just remember to not add the same set several times.</li> <li><code>new HashSet&lt;Set&lt;Integer&gt;&gt;()</code> <em>is</em> an empty set. If you add a set to it, it is no longer empty.</li> <li>A set can be considered to be a binary number. If your range is 2-5, the elements you can select from are <code>{2, 3, 4, 5}</code>. Any subset of this set can be represented as a binary number with four digits, each digit corresponding to an element in the main set, and being 1 if the element is in the subset, and 0 if it is not. So the subset <code>{3, 5}</code> is <code>0101</code> (2 is absent, 3 is present, 4 is absent, 5 is present), and <code>{2, 3, 4}</code> is <code>1110</code>. So if you can find a way of creating all binary numbers with the correct number of digits, and how to create a subset based on each number, you have your algorithm.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload