"""
File contains various functions for creating strings of integers.

Examples:
>>> numstrI(2)
'1'
>>> numstrI(4)
'1 2 4 '
>>> numstrJ(2)
'1'
>>> numstrJ(3)
'1 2 4 '
"""

import sys
import timeit


def numstrI(n):
    """
    Given an integer n > 0, returns string consisting of integers 1 through
     n inclusive.
    
    Examples:
        >>> numstrI(1)
        '1'
        >>> numstrI(3)
        '1 2 4 '
    """
    s = "1"
    for i in range(2,n + 1):
        s += (" " + str(i))
    return(s)


def numstrJ(n):
    """
    Given an integer n > 0, returns string consisting of integers 1 through
     n inclusive.
    
    Examples:
        >>> numstrJ(1)
        '1'
        >>> numstrJ(3)
        '1 2 4 '
    """
    t = ["1"]
    for i in range(2,n + 1):
        t.append(str(i))
    return " ".join(t)


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "usage: ", sys.argv[0], " <n>"
        sys.exit(1)
    
    if int(sys.argv[1]) < 1:
        print "error: n < 1"
        sys.exit(1)
    
    command = 's = numstrI(%1d)' % (int(sys.argv[1]),)
    t = timeit.Timer(command, setup='from __main__ import numstrI')
    print ">>> CPU time of numstrI (1000 executions): " + \
          str(t.timeit(1000)) + " seconds"

    command = 's = numstrJ(%1d)' % (int(sys.argv[1]),)
    t = timeit.Timer(command, setup='from __main__ import numstrJ')
    print ">>> CPU time of numstrJ (1000 executions): " + \
          str(t.timeit(1000)) + " seconds"

