A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

ganeshie8

  • one year ago

how does this powerset function work ``` function power_set(set) { var power_set=[]; for(i=0; i<(1<<set.length); i++) { var subset=[]; for(j=0; j < set.length; j++) { (i&(1<<j)) && subset.push(set[j]); } power_set.push(subset); } return power_set; } ``` https://jsfiddle.net/ng1hL2Ls/

  • This Question is Closed
  1. ganeshie8
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    Haha i don't like javascript either as my fav is perl

  2. nincompoop
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I think the result is pretty good, I just never liked Js because it always looks cluttered. power set is to provide all the subsets of a set. recursive and non-recursive

  3. nincompoop
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    P {a, b, c} {} {a} {b} {c} {a,b} ... and so on and so forth http://rosettacode.org/wiki/Power_Set#JavaScript

  4. ganeshie8
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    wow that looks more compact! im still trying to figure out get how it works

  5. nincompoop
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

  6. ganeshie8
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    looks the python powerset function is also using the leftshift and the logical and

  7. nincompoop
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    https://wiki.python.org/moin/BitManipulation

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.