To avoid rounding problems (such as .1999999999...) it was best to keep the LHS separate from the RHS, keeping both as integers and keeping track of the decimal position, recognizing that leading zeros are possible on the RHS and that trailing zeros need to be trimmed.
10 Lhs=1:Rhs=2:Decpos=1
15 Rhsstr=cutspc(str(Rhs))
20 for I=1 to 30
30 print cutspc(str(Lhs));".";Rhsstr,
35 if Lhs=Rhs then print "*":inc Hitct:else print
40 Newlhs=Lhs+Rhs
50 Lhsstr=cutspc(str(Lhs))
60 Newdecpos=len(Lhsstr)
70 while Newdecpos>Decpos
80 Rhs=Rhs*10:inc Decpos
90 wend
100 while Decpos>Newdecpos
110 Lhs=Lhs*10:inc Newdecpos
120 wend
130 Newrhs=Lhs+Rhs
140 Newrhsstr=cutspc(str(Newrhs))
150 if len(Newrhsstr)>Decpos then
160 :Newlhs=Newlhs+val(left(Newrhsstr,1))
170 :Newrhsstr=mid(Newrhsstr,2,*)
180 while right(Newrhsstr,1)="0"
190 Newrhsstr=left(Newrhsstr,len(Newrhsstr)-1)
200 dec Decpos
205 wend
210 Rhs=val(Newrhsstr):Lhs=Newlhs:Rhsstr=Newrhsstr
220 next
230 print Hitct
The hits are marked with an asterisk(*), and the total of 14 is shown:
1.2
3.3 *
6.6 *
13.2
15.33
48.48 *
96.96 *
193.92
286.113
399.399 *
798.798 *
1597.596
2193.7557
9750.975
10726.95
10822.05726
16548.16548 *
33096.33096 *
66192.66192 *
132385.32384
164769.456225
620994.620994 *
1241989.241988
1483977.3661869
5145846.5145846 *
10291693.0291692
10583385.13208613
23791998.23791998 *
47583996.47583996 *
95167992.95167992 *
14
|
Posted by Charlie
on 2011-11-16 14:32:25 |