Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Forward-difference/Wren/forward-difference.wren
Normal file
18
Task/Forward-difference/Wren/forward-difference.wren
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import "/fmt" for Fmt
|
||||
|
||||
var forwardDiff = Fn.new { |a, order|
|
||||
if (order < 0) Fiber.abort("Order must be a non-negative integer.")
|
||||
if (a.count == 0) return
|
||||
Fmt.print(" 0: $5d", a)
|
||||
if (a.count == 1) return
|
||||
if (order == 0) return
|
||||
for (o in 1..order) {
|
||||
var b = List.filled(a.count-1, 0)
|
||||
for (i in 0...b.count) b[i] = a[i+1] - a[i]
|
||||
Fmt.print("$2d: $5d", o, b)
|
||||
if (b.count == 1) return
|
||||
a = b
|
||||
}
|
||||
}
|
||||
|
||||
forwardDiff.call([90, 47, 58, 29, 22, 32, 55, 5, 55, 73], 9)
|
||||
Loading…
Add table
Add a link
Reference in a new issue