Boustrophedon transform: Difference between revisions

→‎Stretch: Simplified.
(→‎{{header|Wren}}: Added stretch goal.)
(→‎Stretch: Simplified.)
Line 159:
import "./fmt" for Fmt
 
var boustrophedonboustrophedon1000 = Fn.new { |a|
var k = a.count
var cache = List.filled(k, null)
Line 166:
for (j in 0...k) cache[i][j] = BigInt.zero
}
var b = List.filled(k, null)
for (i in 0...k) b[i] = BigInt.zero
b[0] = a[0]
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)
}
for (n in 1...k) b[n] =return T.call(n999, n999)
return b
}
 
System.print("1 followed by 0's:")
var a = ([1] + [0] * 999).map { |i| BigInt.new(i) }.toList
var bs = boustrophedonboustrophedon1000.call(a)[999].toString
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 = boustrophedonboustrophedon1000.call(a)[999].toString
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 = boustrophedonboustrophedon1000.call(a)[999].toString
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 = boustrophedonboustrophedon1000.call(a)[999].toString
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 = boustrophedonboustrophedon1000.call(a)[999].toString
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 = boustrophedonboustrophedon1000.call(a)[999].toString
Fmt.print("1000th term: $20a ($d digits)", bs, bs.count)</syntaxhighlight>
 
9,488

edits