Aurora Visio Studio TOP » Tutorial Exercises » ADVANCED: Factorial (factorial)
ADVANCED: Factorial (factorial)
Aim
Create a macrofilter which computes a factorial for a given value.
The function argument should be provided as Integer.
Input
Single integer for which factorial value should be computed.
Output
Factorial value of the input value.
Hints
This exercise should be solved using macrofilter's registers. All computed steps should be accumulated in a single macrofilter register.
Create the Task macrofilter which computes factorial value using the internal EnumerateIntegers filter.
Labeling connections is explained in this article.
Solution (AVS)
-
Add new Global Parameter of Integer type. Name it N and set its initial value to 5.
-
Add a new register regFactorial of type Long. To do so right-click on the Main macrofilter in the Project Explorer and select Add Macrofilter Register option:
Set its default value to 1 as on the image below.
Label the prevFactorial register as Factorial afterwards.
-
Add filter EnumerateIntegers to ACQUIRE section and set inStart to 1. Label the output as Value.
-
Connect your Global Parameter N**** with inCount.
-
Add a new Formula in the PROCESS section and create a NextFactorial output of Long type:
NextFactorial = Value * Factorial
-
Connect the NextFactorial formula's output with the register's output: nextFactorial .