35 lines
969 B
Plaintext
35 lines
969 B
Plaintext
/* NetRexx*************************************************************
|
|
* Forward differences
|
|
* 18.08.2012 Walter Pachl derived from Rexx
|
|
**********************************************************************/
|
|
Loop n=-1 To 11
|
|
differences('90 47 58 29 22 32 55 5 55 73',n)
|
|
End
|
|
|
|
method differences(a,n) public static
|
|
--arr=Rexx[11] -- array must be declared (zero based)
|
|
arr='' -- alternative: indexed string
|
|
m=a.words
|
|
Select
|
|
When n<0 Then Say 'n is negative:' n '<' 0
|
|
When n>m Then Say 'n is too large:' n '>' m
|
|
Otherwise Do
|
|
Loop i=1 To m
|
|
arr[i]=a.word(i)
|
|
End
|
|
Loop i = 1 to n
|
|
t = arr[i]
|
|
Loop j = i+1 to m
|
|
u = arr[j]
|
|
arr[j] = arr[j]-t
|
|
t = u
|
|
end
|
|
end
|
|
ol=''
|
|
Loop i=n+1 to m
|
|
ol=ol arr[i]
|
|
End
|
|
Say n ol
|
|
End
|
|
End
|