Boustrophedon transform: Difference between revisions
→Stretch: Simplified.
(→{{header|Wren}}: Added stretch goal.) |
(→Stretch: Simplified.) |
||
Line 159:
import "./fmt" for Fmt
var
var k = a.count
var cache = List.filled(k, null)
Line 166:
for (j in 0...k) cache[i][j] = BigInt.zero
}
var T
T = Fn.new { |k, n|
Line 175 ⟶ 172:
return cache[k][n] = T.call(k, n-1) + T.call(k-1, k-n)
}
}
System.print("1 followed by 0's:")
var a = ([1] + [0] * 999).map { |i| BigInt.new(i) }.toList
var bs =
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)
System.print("\nAll 1's:")
a = ([1] * 1000).map { |i| BigInt.new(i) }.toList
bs =
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)
System.print("\nAlternating 1, -1")
a = ([1, -1] * 500).map { |i| BigInt.new(i) }.toList
bs =
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)
System.print("\nPrimes:")
a = Int.primeSieve(8000)[0..999].map { |i| BigInt.new(i) }.toList
bs =
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)
Line 203 ⟶ 199:
a[1] = BigInt.one
for (i in 2..999) a[i] = a[i-1] + a[i-2]
bs =
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)
Line 209 ⟶ 205:
a[0] = BigInt.one
for (i in 1..999) a[i] = a[i-1] * i
bs =
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)</syntaxhighlight>
|