Dear Netlogo community,
I am looking to generate subset of a set of numbers. for example if a set is [1 2 3 4 5] then subset would be [1 2] [1 3] [1 4] [1 5] [ 1 2 3] [1 2 4]....... I know we can generate very easily by using bit manipulation in java. But I have no idea how to implement in Netlogo. I am doomed. Any help would be really appreciated. Thanks
This is easiest to solve using recursion:
The basic idea is that if you want the subsets of
[1 2 3]
, first you find all the subsets of[2 3]
. All of them are themselves subsets of[1 2 3]
, plus if you stick the1
on the front of each of them, the resulting lists are part of the answer too.sample run: