Exemple #1
0
def gray_unrank2_test():

    #*****************************************************************************80
    #
    ## GRAY_UNRANK2_TEST tests GRAY_UNRANK2.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    27 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from gray_rank2 import gray_rank2

    print ''
    print 'GRAY_UNRANK2_TEST'
    print '  GRAY_UNRANK2 unranks a Gray code.'
    print ''
    print '    R  =                         RANK'
    print '    G  =            GRAY_UNRANK2(RANK)'
    print '    R2 = GRAY_RANK2(GRAY_UNRANK2(RANK))'
    print ''
    print '       R       G       R2'
    print ''

    for rank in range(0, 25):
        gray = gray_unrank2(rank)
        rank2 = gray_rank2(gray)
        print '  %6d  %6d  %6d' % (rank, gray, rank2)


#
#  Terminate.
#
    print ''
    print 'GRAY_UNRANK2_TEST:'
    print '  Normal end of execution.'

    return
def gray_unrank2_test ( ):

#*****************************************************************************80
#
## GRAY_UNRANK2_TEST tests GRAY_UNRANK2.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    27 May 2015
#
#  Author:
#
#    John Burkardt
#
  from gray_rank2 import gray_rank2

  print ''
  print 'GRAY_UNRANK2_TEST'
  print '  GRAY_UNRANK2 unranks a Gray code.'
  print ''
  print '    R  =                         RANK'
  print '    G  =            GRAY_UNRANK2(RANK)'
  print '    R2 = GRAY_RANK2(GRAY_UNRANK2(RANK))'
  print ''
  print '       R       G       R2'
  print ''

  for rank in range ( 0, 25 ):
    gray = gray_unrank2 ( rank )
    rank2 = gray_rank2 ( gray )
    print '  %6d  %6d  %6d' % ( rank, gray, rank2 )
#
#  Terminate.
#
  print ''
  print 'GRAY_UNRANK2_TEST:'
  print '  Normal end of execution.'

  return
Exemple #3
0
def subset_gray_rank(n, a):

    #*****************************************************************************80
    #
    ## SUBSET_GRAY_RANK ranks a subset of an N set, using the Gray code ordering.
    #
    #  Example:
    #
    #    N = 4
    #
    #       A       Rank
    #    -------   -----
    #
    #    0 0 0 0       1
    #    1 0 0 0       2
    #    1 1 0 0       3
    #    0 1 0 0       4
    #    0 1 1 0       5
    #    1 1 1 0       6
    #    1 0 1 0       7
    #    0 0 1 0       8
    #    0 0 1 1       9
    #    1 0 1 1      10
    #    1 1 1 1      11
    #    0 1 1 1      12
    #    0 1 0 1      13
    #    1 1 0 1      14
    #    1 0 0 1      15
    #    0 0 0 1      16
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    31 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the total set from which
    #    subsets will be drawn.
    #
    #    Input, integer A(N); A(I) is 1 if element I is in the set,
    #    and 0 otherwise.
    #
    #    Output, integer RANK, the rank of the subset in the Gray code ordering.
    #
    from gray_rank2 import gray_rank2
    from ubvec_to_ui4 import ubvec_to_ui4

    gray = ubvec_to_ui4(n, a)

    rank = gray_rank2(gray)

    rank = rank + 1

    return rank
def subset_gray_rank ( n, a ):

#*****************************************************************************80
#
## SUBSET_GRAY_RANK ranks a subset of an N set, using the Gray code ordering.
#
#  Example:
#
#    N = 4
#
#       A       Rank
#    -------   -----
#
#    0 0 0 0       1
#    1 0 0 0       2
#    1 1 0 0       3
#    0 1 0 0       4
#    0 1 1 0       5
#    1 1 1 0       6
#    1 0 1 0       7
#    0 0 1 0       8
#    0 0 1 1       9
#    1 0 1 1      10
#    1 1 1 1      11
#    0 1 1 1      12
#    0 1 0 1      13
#    1 1 0 1      14
#    1 0 0 1      15
#    0 0 0 1      16
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    31 May 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the total set from which
#    subsets will be drawn.
#
#    Input, integer A(N); A(I) is 1 if element I is in the set,
#    and 0 otherwise.
#
#    Output, integer RANK, the rank of the subset in the Gray code ordering.
#
  from gray_rank2 import gray_rank2
  from ubvec_to_ui4 import ubvec_to_ui4

  gray = ubvec_to_ui4 ( n, a )

  rank = gray_rank2 ( gray )

  rank = rank + 1

  return rank