#! /usr/bin/env python # def ubvec_enum ( n ): #*****************************************************************************80 # ## UBVEC_ENUM enumerates the unsigned binary vectors of length N. # # Discussion: # # A UBVEC is a vector of N binary digits. # # A UBVEC can be interpreted as a binary representation of an # unsigned integer, with the first entry being the coefficient of # 2^(N-1) and the last entry the coefficient of 1. # # UBVEC # # ----- -- # 00000 0 # 00001 1 # 00010 2 # 10000 16 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the length of the vectors. # # Output, integer VALUE, the number of binary vectors. # value = 2 ** n return value def ubvec_enum_test ( ): #*****************************************************************************80 # ## UBVEC_ENUM_TEST tests UBVEC_ENUM. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'UBVEC_ENUM_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' UBVEC_ENUM enumerates unsigned binary vectors' ) print ( ' of N digits' ) print ( '' ) print ( ' N Number' ) print ( '' ) for n in range ( 0, 11 ): n2 = ubvec_enum ( n ) print ( ' %2d %8d' % ( n, n2 ) ) # # Terminate. # print ( '' ) print ( 'UBVEC_ENUM_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ubvec_enum_test ( ) timestamp ( )