Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Also useful to generate subsets since possible the number of subsets of a set of n elements is 2^n.

   for (int i = 0; i << n; i++) {
      ...
   }
(won't work for a large n)

Also... dividing by 2 is (n >> 1) and multiplying by 2 is (n << 1).



looping in order of subset size can be done easily too: https://en.wikipedia.org/wiki/Combinatorial_number_system#Ap...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: