#! /usr/bin/env python # def ubvec_rank_gray ( n, ubvec ): #*****************************************************************************80 # ## UBVEC_RANK_GRAY ranks a UBVEC according to the Gray ordering. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the number of components of the vector. # # Input, integer UBVEC(N), the vector to be printed. # # Output, integer RANK, the rank of the BVEC. # from ubvec_to_ui4 import ubvec_to_ui4 from ui4_rank_gray import ui4_rank_gray ui4 = ubvec_to_ui4 ( n, ubvec ) rank = ui4_rank_gray ( ui4 ) return rank def ubvec_rank_gray_test ( ): #*****************************************************************************80 # ## UBVEC_RANK_GRAY_TEST tests UBVEC_RANK_GRAY. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # import platform from ui4_to_ubvec import ui4_to_ubvec n = 5 print ( '' ) print ( 'UBVEC_RANK_GRAY_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' UBVEC_RANK_GRAY ranks a UBVEC in the Gray ordering.' ) print ( '' ) print ( ' UBVEC Rank' ) print ( '' ) for ui4 in range ( 0, 32 ): ubvec = ui4_to_ubvec ( ui4, n ) rank = ubvec_rank_gray ( n, ubvec ) print ( ' ', end = '' ) for j in range ( 0, n ): print ( '%2d' % ( ubvec[j] ), end = '' ) print ( ' %2d' % ( rank ) ) # # Terminate. # print ( '' ) print ( 'UBVEC_RANK_GRAY_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ubvec_rank_gray_test ( ) timestamp ( )