質問

So I am trying to solve project euler #25 via the big integer brute force method with this module. Everything seems to go properly until the 36'th term, which actually decreases. Then the terms increase as they should, and then decrease again; they never go over 10 million. I have also noticed the 36'th term has all digits correct except one as it is supposed to be 14930352 but I get 4930352 Could this be a problem with my code or a bug in the module?

var bigInt = require('big-integer');
var number = bigInt(1);
var last = bigInt(1);

for(i=0;i<50;i++){
  number = number.add(last);
  last = number.minus(last);
  console.log(number.toString());
}
役に立ちましたか?

解決

Looks like a bug in the library. If you use a tmp variable it works fine.

var bigInt = require('big-integer');
var number = bigInt(1);
var last = bigInt(1);

for(i=0;i<50;i++){
  //number = number.add(last);
  //last = number.minus(last);

  var tmp = number.add(last);
  last = number;
  number = tmp;
  console.log((i + 3) + ":" + number.toString());
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top