|
(Python) def toSystem( n, k ) :
....d = []
....while n > 0 :
........d.append( n % k )
........n /= k
....return d[ -1::-1]
def makeint( l, system = 10 ) :
....i = 0
....for d in l :
........i = i * system + d
....return i
maxn = 1024
it = []
for i in range( 1, maxn ) :
....d = toSystem( i, 2 )
....isLychrel = True
....for j in range( 1000 ) :
........d = toSystem( makeint( d, 2 ) + makeint( d[::-1], 2 ), 2 )
........if d == d[::-1] :
............it.append( j + 1 )
............isLychrel = False
............break
....if isLychrel :
........it.append( 0 )
print 'Maximum iterations for non-seed numbers', max( it )
Lychrel = []
for i in range( len(it) ) :
....if it[i] == 0 :
........Lychrel.append( i + 1 )
print 'Count of binary Lychrel numbers', len( Lychrel )
print 'All binary lichler under', maxn
print 'Decimal form', Lychrel
print 'Binary form', map( lambda x: ''.join( map( str, toSystem( x, 2 ) ) ), Lychrel )
|