Esempio n. 1
0
def main():
    LEN_SPIRAL = 1001
    print( "Creating spiral of length " + str( LEN_SPIRAL ) + "... ")
    sp = spiral( LEN_SPIRAL )
    s = 0
    y = 0
    start = 0
    end = LEN_SPIRAL - 1
    print( "Summing spiral diagonals ... " )
    while not start == LEN_SPIRAL:
        s += sp[ y ][ start ] + sp[ y ][ end ]
        y += 1
        start += 1
        end -= 1
    print( s - 1 ) # center value (1) is counted twice when start == end == 1
Esempio n. 2
0
import sys
import time
from numberwork import spiral

def main():
    LEN_SPIRAL = 1001
    print( "Creating spiral of length " + str( LEN_SPIRAL ) + "... ")
    sp = spiral( LEN_SPIRAL )
    s = 0
    y = 0
    start = 0
    end = LEN_SPIRAL - 1
    print( "Summing spiral diagonals ... " )
    while not start == LEN_SPIRAL:
        s += sp[ y ][ start ] + sp[ y ][ end ]
        y += 1
        start += 1
        end -= 1
    print( s - 1 ) # center value (1) is counted twice when start == end == 1

if __name__ == "__main__":
    if len( sys.argv ) > 1:
        size = int( sys.argv[1] )
        sp = spiral( size )
        for x in range( size ):
            print( sp[ x ] )
    else:
        T0 = time.time()
        main()
        print( "Execution time:", time.time() - T0 )