Jump to content

Nth root: Difference between revisions

adding lambdatalk
(Updated to work with Nim 1.4: added missing parameter types. Replaced 10e-15 which is 10*10^(-15) with 1e-15 which is 10^(-15). Updated result.)
(adding lambdatalk)
Line 1,774:
2.0 ^ 1/2 = 1.414213562373095
</pre>
 
=={{header|Lambdatalk}}==
Translation of Scheme
<lang Scheme>
{def root
{def good-enough? {lambda {next guess tol}
{< {abs {- next guess}} tol} }}
{def improve {lambda {guess num deg}
{/ {+ {* {- deg 1} guess}
{/ num {pow guess {- deg 1}}}} deg} }}
{def *root {lambda {guess num deg tol}
{let { {guess guess} {num num} {deg deg} {tol tol}
{next {improve guess num deg}}
} {if {good-enough? next guess tol}
then guess
else {*root next num deg tol}} }}}
{lambda {num deg tol}
{*root 1.0 num deg tol} }}
-> root
 
{root {pow 2 10} 10 0.1}
-> 2.0473293223683866
{root {pow 2 10} 10 0.01}
-> 2.004632048354822
{root {pow 2 10} 10 0.001}
-> 2.000047868581671
</lang>
 
=={{header|langur}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.