[Solved] I can’t figure out this sequence – 11110000111000110010


There are many possible solutions to this problem. Here’s a reusable solution that simply decrements from 4 to 1 and adds the expected number of 1’s and 0’s.

Loops used : 1

def sequence(n):
    string = ""
    for i in range(n):
        string+='1'*(n-i)
        string+='0'*(n-i)
    return string

print sequence(4)

There’s another single-line elegant and more pythonic way to do this:

print ''.join(['1'*x+'0'*x for x in range(4,0,-1)]) 

Loops used : 1, Lines of code : 1

😉

4

solved I can’t figure out this sequence – 11110000111000110010