FW: [Tutor] Bit Strings [an iterative approach]

Seabrook, Richard rhseabrook at aacc.edu
Wed Oct 22 09:12:24 EDT 2003




-----Original Message-----
From:	Timothy M. Brauch [mailto:tbrauch at mindless.com]
Sent:	Wed 10/22/2003 3:48 AM
To:	Python Tutor
Cc:	
Subject:	Re: [Tutor] Bit Strings  [a recursive approach]
Whilst trying to find all bit strings of a certain length, I struggled.
Danny Yoo was helpful with:

> Have you tried a recursive approach?  It might be useful to outline how to
> solve this recursively, so here goes!  *grin*

============================
I'd not give up the iterative approach so quickly.
As others have noted, you can generate the set of values you want
but merely counting up to 2^N.  However, the values seldom have leading
0 padding to make them N-digit binary numbers, easily convertable to
bit-strings, so the old-fashioned solution is to start counting
at 2^N and count up to 2^(N+1)-1, converting the right-most N digits
in each case.   For example, to get all bit strings of size 5, start
at 2^5 = 32 and count up to 2^(5+1)-1 = 63 converting the right-most
5 digits, like this:
    100000
    100001
    100010
    100011
      ...
      ...
    111111
Dick S.




More information about the Tutor mailing list