Function Problems

Generate Recamán's Sequence in WPS Spreadsheets with LAMBDA and REDUCE

Muhammad TalhaMuhammad Talha Nov 13, 2026 869 views

Question details

The user needs a formula-based way to produce Recamán's sequence in a spreadsheet, using LAMBDA recursion or REDUCE/VSTACK iteration while avoiding duplicate values.

Generate Recamán's Sequence in WPS Spreadsheets with LAMBDA and REDUCE
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
The user wants to generate Recamán's sequence values starting from 0 for a given number of terms directly in WPS Spreadsheets.
Observed behavior
The goal state is a spilled list or array of Recamán's sequence values generated by a LAMBDA or REDUCE formula.
Before you start

Confirm that your WPS Office version supports LAMBDA, REDUCE, VSTACK, and dynamic array formulas. If a formula returns #NAME?, update WPS Office or use the REDUCE/VSTACK method available in your version.

Solution 1Recommended

Generate Recamán's Sequence with a REDUCE and VSTACK Formula

Use this single-cell formula when you want WPS Spreadsheets to create the full sequence without defining a separate named LAMBDA.

This method uses REDUCE to accumulate the sequence and VSTACK to add each new term. It is easier to enter and inspect, but every iteration scans the growing array for duplicates.

1
Open a blank WPS Spreadsheets workbook

Launch WPS Office, open WPS Spreadsheets, and select the cell where you want the sequence to spill, for example A1.

2
Enter the REDUCE/VSTACK formula

Type =LET(n,20,REDUCE(0,SEQUENCE(n,,1),LAMBDA(ac,a,LET(pos,ROWS(ac),prev,TAKE(ac,-1),candidate,prev-pos,next,IF(AND(candidate>0,ISERROR(XMATCH(candidate,ac))),candidate,prev+pos),VSTACK(ac,next))))) and press Enter.

3
Adjust the term count

Change the n value in LET(n,20,...) to generate a different number of Recamán's sequence terms. The formula spills n+1 values because it includes the starting 0.

Generate Recamán's Sequence with a REDUCE and VSTACK Formula
Performance note: For large n, calculation may become slow because each iteration uses XMATCH on the growing sequence and the sequence is not sorted for binary search.
WPS Spreadsheets formula

Generate Recamán's Sequence Directly in WPS Spreadsheets

Use WPS Spreadsheets' LAMBDA, REDUCE, and VSTACK functions to generate Recamán's sequence in one spilled array. Adjust the n value to control how many terms are created, without VBA or manual filling.

  1. 1. Open WPS Spreadsheets: Launch WPS Office and open a blank .xlsx workbook in WPS Spreadsheets.
  2. 2. Enter the sequence formula: Select a cell and enter the REDUCE/VSTACK formula, replacing 20 with your desired term count.
  3. 3. Confirm the spill range: Press Enter and check that the dynamic array fills the visible sequence. Leave enough empty cells below the formula.
  4. 4. Save the workbook: Save the file as .xlsx if you need to share it with Microsoft Excel users.
Creates Recamán's sequence with native LAMBDA/REDUCE formulas instead of manual entryUses dynamic arrays to spill results automatically in WPS SpreadsheetsOpens and saves .xlsx workbooks with full Microsoft Excel formula compatibilityFree, lightweight, and familiar spreadsheet interface for formula users
microsoft office alternative - wps office

Frequently Asked Questions

Why does my LAMBDA formula return #NAME? in WPS Spreadsheets?

#NAME? usually means your WPS Office version does not support LAMBDA, REDUCE, or dynamic array functions. Update WPS Office to a version that supports these functions, or use the REDUCE/VSTACK formula available in your version.

How do I change the number of Recamán's sequence terms?

In the single-cell formula, change the n value inside LET(n,20,...). In the named LAMBDA method, use =Recaman(50,0) or another term count instead of 20.

Why is my Recamán sequence formula slow for large n?

Each iteration searches the growing accumulated sequence with XMATCH. Because Recamán's sequence is not sorted, you cannot reliably use binary or approximate matching to speed up the lookup, so keep n moderate for interactive work.

Can I use these Recamán formulas in Microsoft Excel?

Yes, the same LAMBDA, REDUCE, VSTACK, SEQUENCE, TAKE, and XMATCH formulas work in Excel 365 and Excel 2021. WPS Spreadsheets also preserves these formulas in .xlsx workbooks.

How does the formula avoid duplicate values?

Before accepting the next candidate, the formula checks candidate>0 and uses ISERROR(XMATCH(candidate, accumulated sequence)). If the candidate is already present, the formula adds the current position instead of subtracting it.