Juggler sequence: Difference between revisions
Content added Content deleted
(Realize in F#) |
|||
Line 109: | Line 109: | ||
39: l[n] = 14, h[n] = 233046, i[n] = 3"</lang> |
39: l[n] = 14, h[n] = 233046, i[n] = 3"</lang> |
||
=={{header|F_Sharp|F#}}== |
|||
This task uses [[Isqrt_(integer_square_root)_of_X#F.23]] |
|||
<lang fsharp> |
|||
// Juggler sequence. Nigel Galloway: August 19th., 2021 |
|||
let J n=Seq.unfold(fun(n,i,g,l)->if n=1I then None else let e=match n.IsEven with true->Isqrt n |_->Isqrt(n**3) in Some((i,g,l),if e>i then (e,e,l+1,l+1) else (e,i,g,l+1)))(n,n,0,0)|>Seq.last |
|||
printfn " n l[n] i[n] h[n]\n___________________"; [20I..39I]|>Seq.iter(fun n->let i,g,l=J n in printfn $"%d{int n}%5d{l+1}%5d{g} %A{i}") |
|||
printfn " n l[n] i[n] d[n]\n________________________"; [113I;173I;193I;2183I;11229I;15065I;15845I;30817I;48443I;275485I;1267909I;2264915I;5812827I]|>Seq.iter(fun n->let i,g,l=J n in printfn $"%8d{int n}%5d{l+1}%5d{g} %d{(bigint.Log10>>int>>(+)1) i}") |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
n l[n] i[n] h[n] |
|||
___________________ |
|||
20 3 0 20 |
|||
21 9 4 140 |
|||
22 3 0 22 |
|||
23 9 1 110 |
|||
24 3 0 24 |
|||
25 11 3 52214 |
|||
26 6 3 36 |
|||
27 6 1 140 |
|||
28 6 3 36 |
|||
29 9 1 156 |
|||
30 6 3 36 |
|||
31 6 1 172 |
|||
32 6 3 36 |
|||
33 8 2 2598 |
|||
34 6 3 36 |
|||
35 8 2 2978 |
|||
36 3 0 36 |
|||
37 17 8 24906114455136 |
|||
38 3 0 38 |
|||
39 14 3 233046 |
|||
n l[n] i[n] d[n] |
|||
________________________ |
|||
113 16 9 27 |
|||
173 32 17 82 |
|||
193 73 47 271 |
|||
2183 72 32 5929 |
|||
11229 101 54 8201 |
|||
15065 66 25 11723 |
|||
15845 139 43 23889 |
|||
30817 93 39 45391 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-06-02}} |
{{works with|Factor|0.99 2021-06-02}} |