Hofstadter Figure-Figure sequences: Difference between revisions

Realize in F#
(Added Wren)
(Realize in F#)
Line 843:
</lang>
 
=={{header|F_Sharp|F#}}==
===The function===
<lang fsharp>
// 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
</lang>
===The Tasks===
<lang fsharp>
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)
</lang>
{{out}}
<pre>
1 3 7 12 18 26 35 45 56 69
Unique values=1000 Minimum value=1 Maximum Value=1000
</pre>
===Unbounded n?===
n is bounded in this implementation because it is an signed 32 integer. Within such limit the 10 millionth value will have to be sufficiently unbounded. It can be found in 43 thousandths of sec.
<lang fsharp>
let ffr,ffs=fF 10000000
printfn "%d\n%d (Array.last ffr) (Array.last ffs)
</lang>
1584961838
10004416
{{out}}
=={{header|Factor}}==
We keep lists S and R, and increment them when necessary.
2,171

edits