View Single Post
Old 19-07-2008, 13:36   #14
marco.r
Senior Member
 
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
Codice:
def positionOfGreatestLowerOrEqualThan( matrix, value, rowmin, colmin, rowmax,colmax ):
    i = rowmin
    j = colmin
    while i < rowmax and j < colmax and matrix[i][j] <= value:
        i+=1
        j+=1
    return [i,j]


def findNumber( matrix, value, rowmin, colmin, rowmax, colmax ):
    if rowmin == rowmax or colmin == colmax:
        return False
    [i,j] = positionOfGreatestLowerOrEqualThan( matrix, value, rowmin, colmin, rowmax, colmax )

    if matrix[i-1][j-1] == value:
        return [i-1,j-1]

    return findNumber( matrix, value, rowmin, j, i, colmax ) or findNumber( matrix, value, i, colmin, rowmax, j )
Per pigrizia la ricerca sulla diagonale l'ho fatta lineare, ma basta modificare la prima funzione .
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele

Ultima modifica di marco.r : 19-07-2008 alle 13:38.
marco.r è offline   Rispondi citando il messaggio o parte di esso