Factorial in Sanscript

Example for versions Sanscript 2.2

Sanscript is a fully visual programming language, so no source code is available. See screeshots instead.

First screenshot shows the flowgram of the example. The main part of it is “Repeat” function (an analogue of loop in other languages) which calculates the factorials of numbers from 1 to 16 and stores them in a list. This function has two inlet/outlet pairs which correspond to global variables in other languages: factorial and message. factorial is an integer which stores the current value of factorial. message is a list of text lines n! = (n!). The “Repeat” function has one more inlet N which defines the number of iterations to be done. The inlets are initialized with constants and an empty list, and the loop starts. Once the calculations are done, message has to be displayed. This can be done using Write List as Text function, which writes all elements of list into a single text variable. The separator between elements of the list is defined with sep inlet; in this case it is newline character, generated using “Char” function which converts an ASCII-code into a corresponding character. Finally, the concatenated list is displayed using “Display Message” function.

Second screenshot shows the intrinsics of “Repeat” function. Element marked with “1, 2 …” is loop counter, started with 1 and incremented by 1 each iteration. On each iteration factorial is multiplied by the value of loop counter (using “Times” function). After this its new value is concatenated with loop counter and “! = ” constant string (using “Append Text” function) to produce one line of output. Finally, this line is added to the list message (using “Add Last Item”) function.

Factorial example in Sanscript (flowgram)
Factorial example in Sanscript (flowgram)

Factorial example in Sanscript (repeat)
Factorial example in Sanscript (repeat)