コード例 #1
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def isMorphic( n, k ):
    '''
    Returns true if n to the k power ends with n.
    '''
    digits = getMPFIntegerAsString( real_int( n ) )
    sqr_digits = getMPFIntegerAsString( power( n, real_int( k ) ) )

    start = len( sqr_digits ) - len( digits )
    return 1 if ( sqr_digits[ start : ] == digits ) else 0
コード例 #2
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def isPandigital( n ):
    str = getMPFIntegerAsString( n )

    for c in string.digits:
        if c not in str:
            return 0

    return 1
コード例 #3
0
def getRightTruncations( n ):
    if n < 0:
        raise ValueError( '\'get_right_truncations\' requires a positive argument' )

    str = getMPFIntegerAsString( n )

    for i in range( len( str ), 0, -1 ):
        yield mpmathify( str[ 0 : i ] )
コード例 #4
0
def getLeftTruncations( n ):
    if n < 0:
        raise ValueError( '\'get_left_truncations\' requires a positive argument' )

    str = getMPFIntegerAsString( n )

    for i, e in enumerate( str ):
        yield mpmathify( str[ i : ] )
コード例 #5
0
def sumDigits( n ):
    str = getMPFIntegerAsString( n )

    result = 0

    for c in str:
        result = fadd( result, int( c ) )

    return result
コード例 #6
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def isPalindrome( n ):
    str = getMPFIntegerAsString( n )

    length = len( str )

    for i in range( 0, length // 2 ):
        if str[ i ] != str[ -( i + 1 ) ]:
            return 0

    return 1
コード例 #7
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def getDigits( n, dropZeroes = False ):
    str = getMPFIntegerAsString( n )

    result = [ ]

    for c in str:
        if dropZeroes and c == '0':
            continue

        result.append( int( c ) )

    return result
コード例 #8
0
ファイル: rpnNumberTheory.py プロジェクト: flawr/rpn
def isPolydivisible( n ):
    if real_int( n ) < 0:
        raise ValueError( 'non-negative, real integer expected' )

    strValue = getMPFIntegerAsString( n )

    # a couple of cheats
    if ( len( strValue ) > 4 ) and ( strValue[ 4 ] not in [ '5', '0' ] ):
        return 0

    if ( len( strValue ) > 9 ) and ( strValue[ 9 ] != '0' ):
        return 0

    for i in range( len( strValue ), 1, -1 ):
        current = mpmathify( strValue[ : i ] )

        if not isDivisible( current, i ):
            return 0

    return 1
コード例 #9
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def getRightTruncations( n ):
    str = getMPFIntegerAsString( n )

    for i in range( len( str ), 0, -1 ):
        yield mpmathify( str[ 0 : i ] )
コード例 #10
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def getLeftTruncations( n ):
    str = getMPFIntegerAsString( n )

    for i in range( len( str ) ):
        yield mpmathify( str[ i : ] )
コード例 #11
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def splitNumberByDigits( n ):
    str = getMPFIntegerAsString( n )

    split = len( str ) // 2

    return mpmathify( str[ : split ] ), mpmathify( str[ split : ] )
コード例 #12
0
ファイル: rpnLexicographic.py プロジェクト: flawr/rpn
def reverseDigits( n ):
    return mpmathify( getMPFIntegerAsString( n )[ : : -1 ] )