Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
3
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-1.fs
Normal file
3
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-1.fs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Generate Van Eck's Sequence. Nigel Galloway: June 19th., 2019
|
||||
let ecK()=let n=System.Collections.Generic.Dictionary<int,int>()
|
||||
Seq.unfold(fun (g,e)->Some(g,((if n.ContainsKey g then let i=n.[g] in n.[g]<-e;e-i else n.[g]<-e;0),e+1)))(0,0)
|
||||
1
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-2.fs
Normal file
1
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-2.fs
Normal file
|
|
@ -0,0 +1 @@
|
|||
ecK() |> Seq.take 50 |> Seq.iter(printf "%d "); printfn "";;
|
||||
1
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-3.fs
Normal file
1
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-3.fs
Normal file
|
|
@ -0,0 +1 @@
|
|||
ecK() |> Seq.skip 990 |> Seq.take 50|> Seq.iter(printf "%d "); printfn "";;
|
||||
21
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-4.fs
Normal file
21
Task/Van-Eck-sequence/F-Sharp/van-eck-sequence-4.fs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
open System.Collections.Generic
|
||||
let VanEck() =
|
||||
let rec _vanEck (num:int) (pos:int) (lastOccurence:Dictionary<int, int>) =
|
||||
match lastOccurence.TryGetValue num with
|
||||
| (true, position) ->
|
||||
set num pos (pos - position) lastOccurence
|
||||
| _ ->
|
||||
set num pos 0 lastOccurence
|
||||
and set num pos next lastOccurenceByNumber = seq {
|
||||
lastOccurenceByNumber.[num] <- pos
|
||||
yield next
|
||||
yield! _vanEck next (pos + 1) lastOccurenceByNumber
|
||||
}
|
||||
|
||||
seq {
|
||||
yield 0
|
||||
yield! _vanEck 0 1 (new Dictionary<int, int>())
|
||||
}
|
||||
|
||||
VanEck() |> Seq.take 10 |> Seq.map (sprintf "%i") |> String.concat " " |> printfn "The first ten terms of the sequence : %s"
|
||||
VanEck() |> Seq.skip 990 |> Seq.take 10 |> Seq.map (sprintf "%i") |> String.concat " " |> printfn "Terms 991 - to - 1000 of the sequence : %s"
|
||||
Loading…
Add table
Add a link
Reference in a new issue