tests/python/common/src/lists.python

#!/usr/local/bin/python
# $Id: lists.python,v 1.3 2003/12/30 01:22:55 davidw Exp $
# http://www.bagley.org/~doug/shootout/
# with improvements from Mark Baker

# END COMMENT
import sys

def test_lists(SIZE):
    Li1 = range(1, SIZE + 1)
    Li2 = Li1[:]
    Li3 = []

    # remove each individual item from left side of Li2 and
    # append to right side of Li3 (preserving order)
    # 
    # popping the first element is *expensive*
    #
    #while Li2:
    #    Li3.append(Li2.pop(0))   
    Li2.reverse()
    while Li2:
        Li3.append(Li2.pop())
    while Li3:
        Li2.append(Li3.pop())
    Li1.reverse()
    if Li1[0] != SIZE:
        return 0
    if Li1 == Li2:
        return len(Li1)
    else:
        return 0

def main():
    SIZE = int(sys.argv[1])
    if SIZE < 1:
        SIZE = 1
    result = test_lists(SIZE)
    print result

main()

Generated by GNU enscript 1.6.3.