# The solution for this problem is developed in Daniel Zingaro's lecture slides, which you can find here:
# http://www.cdf.toronto.edu/~heap/148/W14/Lectures/dustin/W4/daniel_zingaro_lecture4.pdf
#
# A binary code of length r is a length r string of bits (each 
# character is 0 or 1). The empty string is the only binary code 
# of length 0.

def gen_binary_codes(r:int) -> set:
  '''Return a set of all the binary strings of length r.
  >>> len(gen_binary_codes(4))
  16
  '''  
  if r == 0:
    return ['']
  else:
    length_r_minus_1_codes = gen_binary_codes(r-1)
    length_r_codes = set()
    for s in length_r_minus_1_codes:
      length_r_codes.add(s + '0')
      length_r_codes.add(s + '1')
    return length_r_codes
  
if __name__ == '__main__':
  import doctest
  doctest.testmod(verbose=True)