本来想去发文挣积分,发现不能发文,就发这儿吧(其实发现那边有大佬写了非常简洁的代码,但是看着太费劲):
from itertools import permutations
def cal_foot( series ):
N = len( series )
foot = 0
for ctx in range( N ):
item = series[ ctx ]
foot += item * pow( 10, N - 1 - ctx )
return foot
option = [ 0, 1, 2, 3, 4, 5 ]
#-----选择符合条件的数组-----
temp = list( permutations( option, 3 ) )
rabbit = []
chick = []
for itx in range( len( temp ) ):
curr = list( temp[ itx ] )
if ( curr[ 0 ] == 0 ) or ( curr[ 2 ] in[ 1, 3, 5 ] ):
continue
#-------------------
tmp = option.copy()
for item in curr:
tmp.remove( item )
#print( curr, ', ', tmp )
xx = list( permutations( tmp, 3) )
for xtx in range( len( xx ) ):
yy = list( xx[ xtx ] )
if ( yy[ 0 ] != 0 ) and ( yy[ 2 ] not in [ 1, 3, 5 ] ):
rabbit_foot = cal_foot( curr )
chick_foot = cal_foot( yy )
if (rabbit_foot / 2 == chick_foot):
print( curr, ', ', yy, ', 只数:', int(rabbit_foot / 4))
rabbit.append( curr )
chick.append( yy )
--
FROM 180.157.99.*