5 ms·
Interesting. Tried it in Pharo. With floats it derails at the same point the Python version derailed in the article. But if you change 4.25 to 17/4, Pharo uses
by Qem 6y ago
Interesting. Tried it in Pharo. With floats it derails at the same point the Python version derailed in the article. But if you change 4.25 to 17/4, Pharo uses rational numbers and it gives a correct result as far as I bothered to try (it bocomes slow after around 35), iteration 38:
x := [ :n |
n = 0
ifTrue: [ 4 ]
ifFalse: [ n = 1
ifTrue: [ 17/4 ]
ifFalse: [ (1500 negated
/ (x value: n - 2) + 815)
/ (x value: n - 1) negated
+ 108 ] ] ].
Transcript clear.
1 to: 38 do: [ :n |
Transcript show: n;
show:' | ';
show: (x value: n) asFloat;
cr ].
Results:
1 | 4.25
2 | 4.470588235294118
3 | 4.644736842105263
4 | 4.770538243626063
5 | 4.855700712589074
6 | 4.910847499082793
7 | 4.945537404123916
8 | 4.966962581762701
9 | 4.980045701355631
10 | 4.987979448478392
11 | 4.992770288062068
12 | 4.995655891506634
13 | 4.997391268381344
14 | 4.998433943944817
15 | 4.999060071970894
16 | 4.999435937146839
17 | 4.999661524103767
18 | 4.9997969007134175
19 | 4.999878135477931
20 | 4.9999268795046
21 | 4.999956127061158
22 | 4.9999736760057125
23 | 4.999984205520272
24 | 4.999990523282228
25 | 4.99999431395856
26 | 4.999996588371256
27 | 4.9999979530213565
28 | 4.999998771812312
29 | 4.999999263087206
30 | 4.9999995578522585
31 | 4.999999734711332
32 | 4.99999984082679
33 | 4.999999904496072
34 | 4.999999942697642
35 | 4.999999965618585
36 | 4.99999997937115
37 | 4.99999998762269
38 | 4.999999992573614