Hey,
As a homework, I have to define a function that returns a frozenset of the positions who are going to explode (the function is_to_explode() is already defined and works). So what this function does, is, given a board, (defined as a list), I’d have to check each elements to know if in this position the element will explode, and that by using a recursive way, well I just don’t see a startpoint. I wrote a function, but actually it doesn't work and I don't see why.
Well if anyone could help, it’d be really great
Thanks in advance.
--------------------------------
As a homework, I have to define a function that returns a frozenset of the positions who are going to explode (the function is_to_explode() is already defined and works). So what this function does, is, given a board, (defined as a list), I’d have to check each elements to know if in this position the element will explode, and that by using a recursive way, well I just don’t see a startpoint. I wrote a function, but actually it doesn't work and I don't see why.
Well if anyone could help, it’d be really great
Thanks in advance.
--------------------------------
def get_all_positions_to_explode(board,start_pos=(1,1)): """ RECURSIVE !!! Return a frozen set of all positions on the given board that have a disk that satisfies the conditions to explode, starting from the given position and proceeding to the top of the board using the next function. - The function returns the empty set if the given start position is None. ASSUMPTIONS - The given board is a proper board. - The given start position is either None or it is a proper position for the given board. NOTE - The second parameter should not be included in the code that is given to the students. They must learn to extend functions with extra parameters with a default value. The documentation of the function must be changed in view of that. """ lst = set() if start_pos[1]> len(board): return frozenset(lst) for col in range(1,len(board[1])): pos = (col,start_pos[0]) if is_to_explode(board,pos)==True: set.add(lst,pos) return get_all_positions_to_explode(board,(1,start_pos[1]+1))