How to resolve the algorithm Catalan numbers step by step in the BQN programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Catalan numbers step by step in the BQN 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 BQN programming language
Source code in the bqn programming language
Cat←{ 0⊸<◶⟨1, (𝕊-⟜1)×(¯2+4×⊢)÷1+⊢⟩ 𝕩 }
Fact ← ×´1+↕
Cat1 ← { # direct formula
⌊0.5 + (Fact 2×𝕩) ÷ (Fact 𝕩+1) × Fact 𝕩
}
Cat2 ← { # header based recursion
0: 1;
(𝕊 𝕩-1)×2×(1-˜2×𝕩)÷𝕩+1
}
Cat¨ ↕15
Cat1¨ ↕15
Cat2¨ ↕15
You may also check:How to resolve the algorithm Terminal control/Hiding the cursor step by step in the Quackery programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the E programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Racket programming language
You may also check:How to resolve the algorithm Guess the number step by step in the Nim programming language
You may also check:How to resolve the algorithm S-expressions step by step in the Julia programming language