EKG sequence convergence: Difference between revisions
Content added Content deleted
(Convergence restoration.) |
(Correcte erroneous Windows-1252->utf8 mojibake) |
||
Line 26: | Line 26: | ||
# Calculate and show here the first 10 members of <code>EKG(10)</code>. |
# Calculate and show here the first 10 members of <code>EKG(10)</code>. |
||
# Calculate and show here at which term <code>EKG(5)</code> and <code>EKG(7)</code> converge ('''stretch goal'''). |
# Calculate and show here at which term <code>EKG(5)</code> and <code>EKG(7)</code> converge ('''stretch goal'''). |
||
;Extra Credıt: |
|||
# Fınd the position ın sequence <code>EKG(2)</code> of the 10000th prıme number 104729 |
|||
;Related Tasks: |
;Related Tasks: |
||
Line 134: | Line 137: | ||
((fun e->i.[e]<-i.[e]+e), (fun l->l|>List.map fN)) |
((fun e->i.[e]<-i.[e]+e), (fun l->l|>List.map fN)) |
||
let fU l= pCache|>Seq.takeWhile(fun n->n<=l)|>Seq.filter(fun n->l%n=0)|>List.ofSeq |
let fU l= pCache|>Seq.takeWhile(fun n->n<=l)|>Seq.filter(fun n->l%n=0)|>List.ofSeq |
||
let rec EKG l ( |
let rec EKG l (α,β)=seq{let b=fU β in if (β=n||β<snd((fG b|>List.maxBy snd))) then fN α; yield! EKG l (fG l|>List.minBy snd) |
||
else fN |
else fN α;yield β;yield! EKG b (fG b|>List.minBy snd)} |
||
yield! seq[1;n]; let g=fU n in yield! EKG g (fG g|>Seq.minBy snd)} |
yield! seq[1;n]; let g=fU n in yield! EKG g (fG g|>Seq.minBy snd)} |
||
⚫ | |||
</lang> |
</lang> |
||
Line 142: | Line 146: | ||
<lang fsharp> |
<lang fsharp> |
||
EKG 2 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
EKG 2 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
||
EKG 3 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
|||
⚫ | |||
EKG 5 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
|||
EKG 7 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
|||
EKG 9 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
|||
EKG 10 |> Seq.take 45 |> Seq.iter(printf "%2d, ") |
|||
printfn "%d" (let n,_,_,_=EKGconv 2 5|>Seq.last in ((Set.count n)+1) |
printfn "%d" (let n,_,_,_=EKGconv 2 5|>Seq.last in ((Set.count n)+1) |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
1, 2, 4, 6, 3, 9,12, 8,10, 5,15,18,14, 7,21,24,16,20,22,11,33,27,30,25,35,28,26,13,39,36,32,34,17,51,42,38,19,57,45,40,44,46,23,69,48 |
|||
1, 3, 6, 2, 4, 8,10, 5,15, 9,12,14, 7,21,18,16,20,22,11,33,24,26,13,39,27,30,25,35,28,32,34,17,51,36,38,19,57,42,40,44,46,23,69,45,48 |
|||
1, 5,10, 2, 4, 6, 3, 9,12, 8,14, 7,21,15,18,16,20,22,11,33,24,26,13,39,27,30,25,35,28,32,34,17,51,36,38,19,57,42,40,44,46,23,69,45,48 |
|||
45 |
45 |
||
</pre> |
</pre> |