N Bit

This N bit algorithm is based on generating the subsets of given size of input,The running time of this particular algorithm can be calculated by 2^n.If n = 4 There should be 2^4 subset which is the number of cycle taken by this particular algorithm.

class NbitString
    def initialize(n)
        @a = Array.new(n)
        @n = n
    end

    def genString(n)
        if n < 1
            @a.each_slice(@n) { |a,b,c| puts [a,b,c]*'  '}
        else
            @a[n-1] = 0
            genString(n-1)
            @a[n-1] = 1
            genString(n-1)
        end
    end
end

nbit = NbitString.new(3)
nbit.genString(3)