How to resolve the algorithm Catalan numbers step by step in the langur programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Catalan numbers step by step in the langur programming language

Table of Contents

Problem Statement

Catalan numbers are a sequence of numbers which can be defined directly: Or recursively: Or alternatively (also recursive):

Implement at least one of these algorithms and print out the first 15 Catalan numbers with each. Memoization   is not required, but may be worth the effort when using the second method above.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Catalan numbers step by step in the langur programming language

Source code in the langur programming language

val .factorial = f if(.x < 2: 1; .x x self(.x - 1))
val .catalan = f(.n) .factorial(2 x .n) / .factorial(.n+1) / .factorial(.n)

for .i in 0..15 {
    writeln $"\.i:2;: \(.catalan(.i):10)"
}

writeln "10000: ", .catalan(10000)

  

You may also check:How to resolve the algorithm Read entire file step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the PHP programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the BQN programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Binary Lambda Calculus programming language
You may also check:How to resolve the algorithm Random number generator (included) step by step in the zkl programming language