Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Display Power Set of 2 Sets of Fibonacci Series n and m?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 400
    Answer it

    Firstly the Fibonacci series is 1,2,3 not 5,8,2 it is not getting corrected. Secondly the correct power set is not getting generated. In the last is I want to generate two Fibonacci series of n and m (they can be same) and generate the power set of two sets of Fibonacci series n and m.

     

    n = [0,1,2]

    n[0] = 1

    n[1] = 2

    def powerSet(items):

        N = len(items)

        # enumerate the 2**N possible combinations

        for i in range(2**N):

            combo = []

            for j in range(N):

                # test bit jth of integer i

                if (i >> j) % 2 == 1:

                    combo.append(items[j])

                else:

                    yield combo

     

    nterms = 3

    count = 0

    i = 0

    if nterms <= 0:

       print("Please enter a positive integer")

    elif nterms == 1:

       print("Fibonacci sequence upto",nterms,":")

       print(n[0])

    else:

       print("Fibonacci sequence upto",nterms,"terms:")

       while count < nterms:

           print(n[i],end=' , ')

           nth = n[i] + n[i+1]

           # update values

           n[i] = n[i+1]

           n[i+1] = nth

           count += 1

     

    i=0

    for i in range(len(n)):

        print("\n",n[i], sep = ", ")

        i+=1

    powerSet(n)

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: