Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you think of a list of booleans as a list of bits of fixed length, there is a very simple solution: Count!</p> <p>If you want to have all combinations of 4 booleans, count from 0 to 15 (2^4 - 1) -- then interpret each bit as one of the booleans. For simplicity I'll use a for-loop, but you can also do it with a recursion:</p> <pre><code>let size = 4 in (* '1 lsl size' computes 2^size *) for i = 0 to (1 lsl size) - 1 do (* from: is the least significant bit '1'? *) let b0 = 1 = ((i / 1) mod 2) in let b1 = 1 = ((i / 2) mod 2) in let b2 = 1 = ((i / 4) mod 2) in (* to: is the most significant bit '1'? *) let b3 = 1 = ((i / 8) mod 2) in (* do your thing *) compute b0 b1 b2 b3 done </code></pre> <p>Of course you can make the body of the loop more general so that it e.g. creates a list/array of booleans depending on the size given above etc.; The point is that you can solve this problem by enumerating all values you are searching for. If this is the case, compute all integers up to your problem size. Write a function that generates a value of your original problem from an integer. Put it all together.</p> <p>This method has the advantage that you do <strong>not</strong> need to first create all combinations, before starting your computation. For large problems this might well save you. For rather small size=16 you will already need <em>65535 * sizeof(type)</em> memory -- and this is growing exponentially with the size! The above solution will require only a constant amount of memory of <em>sizeof(type)</em>.</p> <p>And for science's sake: Your problem is <strong>NP-complete</strong>, so if you want the exact solution, it will take exponential time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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