Can you write a program to generate a specific pattern or structure? For this exercise, generate an n x n matrix containing the integers from 1 through n² in clockwise spiral order. Implement generate_spiral(n), which accepts a positive integer and returns a list of row lists. Example: n = 3 returns [[1,2,3],[8,9,4],[7,6,5]]; n = 1 returns [[1]]. Use constant extra state beyond the returned matrix.
def generate_spiral(n):