Jump to content

Golden ratio/Convergence: Difference between revisions

Added Shen before Wren.
m (→‎{{header|Phix}}: split the overlong printf)
(Added Shen before Wren.)
Line 1,126:
<pre>Result: 987/610 (1.618032786885246) after 14 iterations
The error is approximately -1.2018646489142526e-6</pre>
 
=={{header|Shen}}==
 
I plugged in a value for <math>\phi</math> rather than write a sqrt procedure or see what there might be in the standard library. (''Actually I wrote a sqrt procedure, but eventually decided to do this instead.'')
 
<syntaxhighlight lang="shen">
(define iterate
PHI N ->
(let PHI1 (+ 1 (/ 1 PHI))
N1 (+ N 1)
DIFF (* 100000 (- PHI1 PHI))
(if (and (<= -1 DIFF) (<= DIFF 1))
[PHI1 N1 (- PHI1 1.618033988749895)]
(iterate PHI1 N1))))
 
(print (iterate 1 0))
</syntaxhighlight>
 
{{out}}
I ran this with shen-scheme.
<pre>[1.6180327868852458 14 -1.2018646493583418e-6]</pre>
 
=={{header|Wren}}==
1,448

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.