私はGroovyが初めてです。フィボナッチ数列とそのプロパティを解いています。私はこのようなグルーヴィーなコードを持っています:
a = new BigInteger[2][2]
a[0][0] = 1
a[0][1] = 1
a[1][0] = 1
a[1][1] = 0
temp = new BigInteger[2][2]
temp = a
def testFun(def a,BigInteger n) {
if(n == 1)
return a
b = new BigInteger[2][2]
def sum = 0
for ( c = 0 ; c < 2 ; c++) {
for ( d = 0 ; d < 2 ; d++ )
{
for ( k = 0 ; k < 2 ; k++ )
{
sum = sum + temp[c][k] * a[k][d];
}
b[c][d] = sum
sum = 0;
}
}
testFun(b,n-1)
}
c = new BigInteger[2][2]
BigInteger n = 90
if( n % 2 == 0 )
{
c = testFun(a,n.divide(2))
temp = c
c = testFun(c,2)
}
println c[0][1]
私は次のような答えを得ています:
2880067194370816120
しかし、n 値を say に変更すると5090
、次のような大きなエラーが発生します。
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
at fibb.testFun(fibb.groovy:24)
at fibb$testFun.callCurrent(Unknown Source)
何が悪かったのか?なぜこのエラーが発生するのですか?