'''
Created on Sep 2, 2012

@author: ola
'''
import random
import matplotlib.pyplot as plt

# width of drawn screen
WIDTH = 80

def visualize(n):
    '''
    Returns a string that represents the location of the random walker
    with a location of zero in the mdidle of the "screen"
    '''
    
    # put zero in middle of screen
    location = n + WIDTH/2
    if location < 0:
        return "|*" + " "*(WIDTH-1) + "|"
    elif location > WIDTH-1:
        return "|" + " "*(WIDTH-1) + "*|"
    else:
        return "|" + " "*location + "B" + " "*(WIDTH-1-location) + "|"
    
def walk(n,stride):
    pos = 0
    locs = []
    for x in range(1,n):
        print visualize(pos), pos,"\t",x
        if random.randint(1,2) == 1:
            pos += stride
        else:
            pos -= stride
        locs.append(pos)
        
    #plt.plot(locs,'ro')
    #plt.show()
            
    return abs(pos)


if __name__ == '__main__':
    x = walk(500,1)
    print x