Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
|
|
@ -0,0 +1,29 @@
|
|||
prefix sma_
|
||||
global p[] ind[] sum[] smpl[][] .
|
||||
func new p .
|
||||
p[] &= p
|
||||
ind[] &= 0
|
||||
sum[] &= 0
|
||||
smpl[][] &= [ ]
|
||||
return len p[]
|
||||
.
|
||||
func get id x .
|
||||
ind[id] = (ind[id] + 1) mod1 p[id]
|
||||
ind = ind[id]
|
||||
if len smpl[id][] < ind
|
||||
len smpl[id][] ind
|
||||
else
|
||||
sum[id] -= smpl[id][ind]
|
||||
.
|
||||
sum[id] += x
|
||||
smpl[id][ind] = x
|
||||
return sum[id] / len smpl[id][]
|
||||
.
|
||||
prefix
|
||||
#
|
||||
sma5 = sma_new 5
|
||||
sma3 = sma_new 3
|
||||
numfmt 2 4
|
||||
for v in [ 1 2 3 4 5 5 4 3 2 1 ]
|
||||
print sma_get sma3 v & " " & sma_get sma5 v
|
||||
.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import "/fmt" for Fmt
|
||||
import "./fmt" for Fmt
|
||||
|
||||
var sma = Fn.new { |period|
|
||||
var i = 0
|
||||
|
|
@ -21,5 +21,5 @@ var sma5 = sma.call(5)
|
|||
System.print(" x sma3 sma5")
|
||||
for (x in [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) {
|
||||
Fmt.precision = 3
|
||||
System.print("%(Fmt.f(5, x)) %(Fmt.f(5, sma3.call(x))) %(Fmt.f(5, sma5.call(x)))")
|
||||
Fmt.print("$5f $5f $5f", x, sma3.call(x), sma5.call(x))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue