def naorthreshold(lmbda, mu, costofbalking):
    """
    Function to return Naor's threshold for optimal behaviour in an M/M/1 queue. This is taken from Naor's 1969 paper: 'The regulation of queue size by Levying Tolls'

    Arguments:
        lmbda - arrival rate (float)
        mu - service rate (float)
        costofbalking - the value of service, converted to time units. (float)

    Output: A threshold at which optimal customers must no longer join the queue (integer)
    """
    n = 0  # Initialise n
    center = mu * costofbalking  # Center mid point of inequality from Naor's aper
    rho = lmbda / mu
    while True:
        LHS = (n*(1-rho)- rho * (1-rho**n))/((1-rho)**2)
        RHS = ((n+1)*(1- rho)-rho*(1-rho**(n+1)))/((1-rho)**2)
        if LHS <= center and center <RHS:
            return n
        n += 1