How to resolve the algorithm Motzkin numbers step by step in the F# programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Motzkin numbers step by step in the F# programming language

Table of Contents

Problem Statement

The nth Motzkin number (denoted by M[n]) is the number of different ways of drawing non-intersecting chords between n points on a circle (not necessarily touching every point by a chord). By convention M[0] = 1.

Compute and show on this page the first 42 Motzkin numbers or, if your language does not support 64 bit integers, as many such numbers as you can. Indicate which of these numbers are prime.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Motzkin numbers step by step in the F# programming language

Source code in the fsharp programming language

// Motzkin numbers. Nigel Galloway: September 10th., 2021
let M=let rec fN g=seq{yield List.item 1 g; yield! fN(0L::(g|>List.windowed 3|>List.map(List.sum))@[0L;0L])} in fN [0L;1L;0L;0L]
M|>Seq.take 42|>Seq.iter(printfn "%d")


  

You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the Latitude programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Oforth programming language
You may also check:How to resolve the algorithm Greedy algorithm for Egyptian fractions step by step in the D programming language
You may also check:How to resolve the algorithm McNuggets problem step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Ursala programming language