Generate an Ulam Number Spiral in WPS Office Spreadsheets with LET, LAMBDA, and REDUCE
Question details
The user wants to generate a large Ulam number spiral in a spreadsheet using non-recursive formulas built with LET, LAMBDA, REDUCE, and dynamic arrays, and to compare frame-based and coordinate-based approaches.

- Product
- WPS Office Spreadsheets
- Device & OS
- not provided
- Scenario
- Creating a large Ulam spiral in a worksheet for mathematical visualization without relying on recursion or VBA.
- Observed behavior
- The user seeks a practical formula that scales to large odd-numbered matrices and avoids recursion limits, with a comparison between the frame-based REDUCE method and a direct MAKEARRAY method.
Confirm that your WPS Office Spreadsheets version supports dynamic array functions such as LET, LAMBDA, REDUCE, MAKEARRAY, and SEQUENCE. For large spirals, close unnecessary workbooks and consider setting calculation options to Manual while you develop the formula.
Frame-Based REDUCE Formula Starting from a 3×3 Core
Use this method when you want a practical non-recursive approach that expands the spiral outward by odd-numbered layers using LET, LAMBDA, and REDUCE.
This method handles the 3×3 core separately and appends each new outer ring as a frame. It is often easier to trace and debug because the expansion layers map directly to the Ulam spiral structure.
Open WPS Office Spreadsheets, select cell A1, and type a 3×3 array constant such as ={17,16,15;18,5,4;19,6,3} in the formula bar, then press Enter to create the starting core.
Go to the Formulas tab, click Name Manager, and choose New. Create a name like UlamFrame and enter the LET/LAMBDA logic that reads the current matrix, builds the next odd layer, and returns the expanded square.
In an empty cell, enter a formula such as =REDUCE(A1#,SEQUENCE((n-3)/2,1,5,2),LAMBDA(m,s,UlamFrame(m,s))) replacing n with the desired odd width. Press Enter to spill the full Ulam spiral.

Coordinate-Based MAKEARRAY Formula for Each Cell
Use this method when you want a single formula that calculates each cell directly from its ring, side, and offset, potentially avoiding repeated padding and stacking for large matrices.
Build a Large Ulam Number Spiral in WPS Office Without Recursion
Use WPS Office Spreadsheets' support for dynamic array functions such as LET, LAMBDA, REDUCE, and MAKEARRAY to generate a large Ulam spiral directly in a worksheet. The workbook remains fully compatible with Microsoft Excel .xlsx files, so you can share your formula model without conversion issues.
- 1. Open WPS Office Spreadsheets: Launch WPS Office, click Spreadsheets, and create a new blank workbook.
- 2. Enter the core and enable dynamic arrays: Select cell A1 and enter the 3×3 Ulam core array constant, then confirm dynamic array spill is working in your version.
- 3. Add the LET/LAMBDA formula: Click the Formulas tab > Name Manager > New, and define the frame expansion or MAKEARRAY calculation using LET, LAMBDA, REDUCE, and SEQUENCE.
- 4. Spill and save the workbook: Apply the formula in a blank cell to generate the spiral, then click File > Save As and choose .xlsx to keep full Microsoft Excel compatibility.

Frequently Asked Questions
Does WPS Office Spreadsheets support LET, LAMBDA, and REDUCE for Ulam spiral formulas?
Yes, current WPS Office versions support dynamic array functions including LET, LAMBDA, REDUCE, MAKEARRAY, and SEQUENCE. Confirm your version by entering =LET(x,1,x) in a cell; if it returns 1, these functions are available.
Can I generate an Ulam spiral without recursion or VBA?
Yes. Use either the frame-based REDUCE method that expands from a 3×3 core or a coordinate-based MAKEARRAY formula that calculates each cell from its ring, side, and offset.
Which method is faster for very large Ulam spirals?
The REDUCE frame method is practical and easy to trace, but a MAKEARRAY formula may perform better because it calculates each cell directly and avoids repeated padding and stacking. Test both with the same target size and calculation mode.
How do I change the starting number or spiral direction?
Adjust the 3×3 core array for the frame-based method, or modify the ring, side, and offset logic inside the MAKEARRAY LAMBDA. The direction is controlled by the order in which you fill each outer frame.
Can I save the resulting workbook for Microsoft Excel users?
Yes. In WPS Office Spreadsheets, click File > Save As and choose .xlsx. The formulas and spill ranges remain compatible with Microsoft Excel when opened there.




