#### samdthompson

##### New member

- Joined
- Aug 7, 2018

- Messages
- 8

- Reaction score
- 0

- Points
- 1

- Excel Version(s)
- 365

Hello, I have built a recursive Lambda which does not recurse. I cannot for the life of me work out which bit is going wrong other than the recursion. The main formula works well and manual recursion works exactly as it should. The aim is to remove "R" from the grid based on how many X's there are around them. The recursion should stop when there are no additional X's to remove. Note There may still be some X's left but not any that require removal.

Formula:

=_ValueRecursion(_rng,_initial_value)

Named Range:

=LAMBDA(_rng,_initial_value,

LET(

_up, OFFSET(_rng, -1, 0),

_right, OFFSET(_rng, 0, 1),

_down, OFFSET(_rng, 1, 0),

_left, OFFSET(_rng, 0, -1),

_x, MAP(_up, _right, _down, _left, LAMBDA(u,r,d,l, OR(u = "x", r = "x", d = "x", l = "x"))),

_txttosplit, _up & "," & _right & "," & _down & "," & _left, _txtsplit, LEN(_txttosplit) - LEN(SUBSTITUTE(_txttosplit, "R", "")),

_calc, IF(_rng = "W", "W", IF(_rng = "", "", IF(_x * _txtsplit = 1, "X", _rng))),

_current_count, COUNTA(FILTER(TOCOL(_calc), TOCOL(_calc) = "X")),

_finish, IF(_initial_value = _current_count, _calc, _ValueRecursion(_calc, _current_count)),

_finish)

)

Cheers

Formula:

=_ValueRecursion(_rng,_initial_value)

Named Range:

=LAMBDA(_rng,_initial_value,

LET(

_up, OFFSET(_rng, -1, 0),

_right, OFFSET(_rng, 0, 1),

_down, OFFSET(_rng, 1, 0),

_left, OFFSET(_rng, 0, -1),

_x, MAP(_up, _right, _down, _left, LAMBDA(u,r,d,l, OR(u = "x", r = "x", d = "x", l = "x"))),

_txttosplit, _up & "," & _right & "," & _down & "," & _left, _txtsplit, LEN(_txttosplit) - LEN(SUBSTITUTE(_txttosplit, "R", "")),

_calc, IF(_rng = "W", "W", IF(_rng = "", "", IF(_x * _txtsplit = 1, "X", _rng))),

_current_count, COUNTA(FILTER(TOCOL(_calc), TOCOL(_calc) = "X")),

_finish, IF(_initial_value = _current_count, _calc, _ValueRecursion(_calc, _current_count)),

_finish)

)

Cheers

Last edited: