Python Contingency Table Enumerator

Job ID: 40337201

Budget: $30 – $250 CAD

I need a clean, self-contained Python script that systematically iterates through every possible contingency table with

• N rows, each summing to R
• W columns, each summing to M
These values will be integers

The routine must return a single Python object—a list containing each valid table (each table can be a nested NumPy array or plain list of lists; whichever is cleaner in your implementation). Because I will be running post-processing in NumPy, please build the core logic around that library and import only what is essential. Alternatively, and preferably, the code is an iterator so that not all tables need to be in memory at the same time.

Add only short, purposeful inline comments so that the flow is easy to follow without crowding the code. No extra documentation blocks are necessary—just enough cues to show why each step is there.

Key expectations
1. A callable function, e.g. `enumerate_tables(N, W, R, M) -> list`
2. Guaranteed coverage of the entire solution space without duplicates
3. Reasonable run-time for moderate sizes (I understand that the problem is combinatorial; efficiency matters but perfect optimisation isn’t required)
4. A quick demo section at the bottom showing the function in action on a small example

Deliver the finished `.py` file only; no need for external data or write-ups.