How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the F# programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the F# programming language

Table of Contents

Problem Statement

These two sequences of positive integers are defined as:

The sequence

S ( n )

{\displaystyle S(n)}

is further defined as the sequence of positive integers not present in

R ( n )

{\displaystyle R(n)}

. Sequence

R

{\displaystyle R}

starts: Sequence

S

{\displaystyle S}

starts:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the F# programming language

Source code in the fsharp programming language

// Populate R and S with values of Hofstadter Figure Figure sequence. Nigel Galloway: August 28th., 2020
let fF q=let R,S=Array.zeroCreate<int>q,Array.zeroCreate<int>q
         R.[0]<-1;S.[0]<-2
         let rec fN n g=match n=q with true->(R,S)
                                      |_->R.[n]<-R.[n-1]+S.[n-1]
                                          match S.[n-1]+1 with i when i<>R.[g]->S.[n]<-i; fN (n+1) g
                                                              |i->S.[n]<-i+1; fN (n+1) (g+1)
         fN 1 1


let ffr,ffs=fF 960
ffr|>Seq.take 10|>Seq.iter(printf "%d "); printfn ""

let N=Array.concat [|ffs;(Array.take 40 ffr)|] in printfn "Unique values=%d Minimum value=%d Maximum Value=%d" ((Array.distinct N).Length)(Array.min N)(Array.max N)


let ffr,ffs=fF 10000000
printfn "%d\n%d (Array.last ffr) (Array.last ffs)


  

You may also check:How to resolve the algorithm List rooted trees step by step in the jq programming language
You may also check:How to resolve the algorithm Flipping bits game step by step in the Tcl programming language
You may also check:How to resolve the algorithm Spinning rod animation/Text step by step in the REXX programming language
You may also check:How to resolve the algorithm Take notes on the command line step by step in the Forth programming language
You may also check:How to resolve the algorithm String matching step by step in the Tcl programming language