'''
This code is developed by professor Jørn Vatn. The code can be used
by students and employees at NTNU. The code comes with no warranties.

You are not allowed to use the code for commercial purposes without
written permission from Jørn Vatn
'''
LowValue  = 0
HighValue = 5 
def initComb(n):
    import numpy as np
    arr = np.zeros(n, dtype = int)
    arr[0]=LowValue-1 
    return arr

def nxtComb(arr):
    '''    
    Draw the next combination of arr(). If the first element is invalid
    the table is reset. The function returns FALSE for calls after
    returning the last combination.
    NB, uses INTEGER values
    '''
    n = len(arr)
    if arr[0] < LowValue:
        for i in range(0,n):
            arr[i] = LowValue
        return True
    for i in range(n-1,-1, -1):
        if arr[i] < HighValue: 
            arr[i] +=  1
            return True
        elif i == 0: 
            return False
        else:
            arr[i] = LowValue
    



