Recursion

let’s try to Understand Recursion with this Simple Example

# To understand recursion, see the bottom of this file
.
. (at the end of the code...)
.
# To understand recursion, see the top of this file

Just Kidding,

Recursion is a powerful concept in computer programming that allows a function or procedure to call itself. In the context of Appian, a low-code development platform, recursion can be utilized to solve complex problems or perform repetitive tasks in a more concise and efficient manner.

Appian supports recursion by allowing functions or expressions to call themselves within their own definition. This enables developers to write recursive algorithms that break down a problem into smaller sub-problems and solve them iteratively.

When using recursion in Appian, it’s important to define appropriate termination conditions or base cases to prevent infinite loops. These base cases ensure that the recursion eventually reaches a stopping point and returns a result.

By leveraging recursion, developers can write elegant and compact code for tasks that involve repetitive or hierarchical operations. Recursive algorithms are particularly useful when dealing with data structures like trees, graphs, or nested collections.

However, it’s essential to use recursion judiciously and consider its potential impact on performance and memory usage. Recursive functions can consume additional stack space for each recursive call, which may lead to stack overflow errors if not managed carefully.

In summary, recursion in Appian provides a powerful mechanism for solving complex problems by breaking them down into simpler sub-problems. It enables developers to write concise and elegant code but requires careful consideration of termination conditions and potential resource limitations.

Let’s Understand With a Few Implementations in Appian with Our Famous Fibonacci Series

A sample Fibonacci series would look like 0,1,1,2,3,5,8,13,21 . . . . . . and so on. We Will Be implementing this Using Recursion and Output Would Look Like This.

Create an Expression Rule LA_recursion and we will be calling This Rule inside this rule.

/*This Code is Written By DSniper*/
if(
  ri!num > 2,
  rule!LA_recursion(ri!num - 1) + rule!LA_recursion(ri!num - 2),
  if(ri!num = 0, 0, 1)
)
Now Its ready to Run . To Execulte this we will be Opening an Un-named Rule and Will Execute Our Expression Rule. 

Let’s deep Dive Further and see One more example of Recursion I am sure it would be very useful in Playing with Excel.

So the Objective is to Generate Characters of Given Numbers but in Excel Format.

Ex: 1 – A, 27 – AA , 16384 – XFD and so on

We will be Implementing this with Recursion,

Note:- Excel also has Validations means the max Columns can be up to 16,384 .

We Will be Implementing a Problem statement with a number greater than zero validation ✅ taking into Consideration that Row validations Can be Implemented by Fellow Programmers.

Sign of the Horns on Telegram Telemoji (March 2023)
/*This Code is written By DSniper*/
if(
  ri!columnNumber <= 0,
  "",
  a!localVariables(
    local!columnNumber: ri!columnNumber - 1,
    local!numberofChars: 26,
    local!asciof_A: 65,
    concat(
      rule!LA_columnIndexes(
        columnNumber: int(local!columnNumber / local!numberofChars)
      ),
      char(
        local!asciof_A + mod(local!columnNumber, local!numberofChars)
      )
    ),

  )
)

In This Manner, we Can easily generate Values For A given Number.

That’s All for Today Will meet Soon With Another block of Strategy.

Till then please provide your Valuable Feedback and Keep Shining.

Let Us know if you Found Something Valuable


Discover more from Appian Tips

Subscribe to get the latest posts sent to your email.

Leave a Reply

Up ↑

Discover more from Appian Tips

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Appian Tips

Subscribe now to keep reading and get access to the full archive.

Continue reading