Forward difference: Difference between revisions

Added parameter types to make the program able to compile with Nim 1.4. Changed code to avoid to use a slice which implies a copy.
(Add Plain English)
(Added parameter types to make the program able to compile with Nim 1.4. Changed code to avoid to use a slice which implies a copy.)
Line 1,982:
 
=={{header|Nim}}==
<lang nim>proc dif(s: seq[int]): seq[int] =
result = newSeq[int](s.len-1)
for i, x in s[10..<s.high]:
result[i] = xs[i+1] - s[i]
 
proc difn(s,: seq[int]; n: int): seq[int] =
if n > 0: difn(dif(s), n-1)
else: s
 
const s = @[90, 47, 58, 29, 22, 32, 55, 5, 55, 73]
echo difn(s, 0)
Anonymous user