Square root by hand: Difference between revisions

Realize in F#
m (→‎{{header|REXX}}: added a word to the REXX section header.)
(Realize in F#)
Line 32:
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>
// Square Root of n 'By Hand' (n as bigint >= 1). Nigel Galloway: October 14th., 2020
let rec fN n g=match n/100I with i when i=0I->(n%100I)::g |i->fN i ((n%100I)::g)
let fG n g=[9I.. -1I..0I]|>Seq.map(fun g->(g,g*(20I*n+g)))|>Seq.find(fun(_,n)->n<=g)
let fL(n,g,l)=let c,n=match n with []->(g*100I,[]) |_->((List.head n)+g*100I,List.tail n)
let x,y=fG l c in Some(int x,(n,c-y,l*10I+x))
let sR n g l=Seq.unfold fL (fN n [],0I,0I)|>Seq.take l|>Seq.iteri(fun i n->printf "%s%d" (if i=(g+1)/2 then "." else "") n); printfn "\n"
 
sR 2I 1 480; sR 1089I 2 8
</lang>
{{out}}
<pre>
1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459686201472851741864088919860955232923048430871432145083976260362799525140798968725339654633180882964062061525835239505474575028775996172983557522033753185701135437460340849884716038689997069900481503054402779031645424782306849293691862158057846311159666871
 
3.3000000
</pre>
=={{header|Go}}==
{{trans|Visual Basic .NET}}
2,172

edits