Skip to content

Instantly share code, notes, and snippets.

@voltrevo
Last active November 17, 2015 23:18
Show Gist options
  • Save voltrevo/ed3868ac26f8b0b3d5b2 to your computer and use it in GitHub Desktop.
Save voltrevo/ed3868ac26f8b0b3d5b2 to your computer and use it in GitHub Desktop.
bignum fibonacci
'use strict';
var bignum = require('bignum');
var fib = function(n) {
var a = bignum(0);
var b = bignum(1);
for (var i = 1; i < n; i++) {
a = a.add(b);
var c = a;
a = b;
b = c;
}
return b;
};
var wrap = function(str, lineLen) {
var lines = [];
while (str.length > 0) {
var line = str.substring(0, lineLen);
str = str.substring(line.length);
lines.push(line);
}
return lines.join('\n');
};
console.log(wrap(
fib(25090).toString(),
80
));
14138680148844875451020132978879778219136939822638991024672188781475663243760802
36593547286212241939329126821804374002888329643531094171128077712640546290768334
79952552220748248070847601718696612832312926392522805397239751124737354238046701
85210823126294698146755484795851698652529723409495686003968638229063848573412498
26198852263385118075035462201491838345032112697928840499619710853161605471722330
87489929548433362610304479414471716585130371703932535216697145025564599066776145
73447916546178955287614394648222354994887265366611422569650003340477041302936685
05193706777177359655676737285183937637248163142405769549841139309859602236907535
34913167921925832743639598324582916590345044313036629835137406904292069132050491
88422015830736069556485435107324284665534662949923195882397343007611211038427177
26112741112187148019516263200741621411324149692999908391923118000977973583553400
07628640958839658689444170881414076670404558541651220898321527755882663327474502
06930528306706148601202903209449568481345115144434745929124523699477616147118060
53782137087429549526378380765781971838475755173117261717173554368482706745075699
54812906608656404413948277320666947965881495661672543028910636026559784317495885
58969168342059637960091565798685268519188947974103679138113689871173808520845970
44480065702088207952488539629924793068500759192004089097745205555569953139819923
78338727611341386945372573150150996379306971339280652601022648973201322612567388
01349134328404367090400851686098029216045092834827639385453204329559940483140043
91496794085364049270022711137882353752449633140676495759284766110897571243651436
73180688990491030968621049198768298575406529916378507369775594184911883574827677
94478417199098150530535812052395694914792360247732555954023765099408867341946813
05861654025318152074689350809559282642789581788540503988601064119104492051222235
76312393283698558997166082415172475391155111090576587863182486403393199469594990
26570252116171462452531961246232915190592589558404036434400706141424526152400527
35251422822354840071164923978182924250521108858028494118035531159954562640970524
86002653837838188667629405365300680259243412123601220122432487708660656502850152
60787123817004244263943137338581574835578301150311687892455007839108232880738120
04974417554488020164496210241971821560807468550237004125173854441624919880063545
28855222069278448763840775643540355390159577580604175381596506546313285867672900
67676243902525381089517709037030325215850598980040811973249598447610539880505979
72250225972267848359640171161499806957557147995255191388783836394244209968805010
12594738790733939836665656126998428155809970229534046240125779273753928878188367
81033645381388459147089086185581830330942167476752794280741518106518209000832010
92922700438352146085651372099681755066417626793744695729519022273645839764399824
42477449385545644651818457590144812215762455531768438196813171498792019469593490
64835934047638907607780757175039094736237034896568194079368017611138166221066151
50508854063658414126324628872863705558243466003288904323850337394079172629668325
84292369281546908825198146856280794758075682992928327173887672047129836690427646
05838928800727393885880140014923856444756279283052396725026692676338518973836058
32203710077180563100061064795171780689929744932344878822372956998086588306590537
62370681911865790965005760629040547835684466274968591018596091076921111836788535
24661645560391606111854587796542414721110495574813578826967868106527888849603081
07513920418824735709225707000676073855328008847971007225231225260641996699845804
75003086992216807154343569906404026705193775104295616299737982753688679636547252
09829515956012793523745628972528773250408811151936817459585116286339264366692331
71582476681425172300686502354407636129546501625847526028095657326761904699135523
91202560374817914946531348711053517080761526895599912296146115263438779838059508
56336061898516348040823728278653991023379132968849337201673957585270868583943821
06714083638302862833450877100749594949941331043884353470265887147139673050539669
12956853719306891972429518881245867403465889476092385073893401008063201014635590
04143490175118543352641353966823512429710618466860073761742776208138313848654927
26839370285213597527172002390732574616189522002367755563656795944501021417178972
12269735062854827564775796749614318779580503933056001183989535463310286154310592
47497114859600261013101666192654029314478239859492458815308561599510935816587819
06880870252027739084720704231654252356388920453387850801708584266308128308251990
32191498267221627903574175791932889713670132325430454985681930633437927360323262
26199070364563904309258853515833330046749250144204504497082966227840232324324216
10587800411324613710416304338381617399958393840069908769542920780350042552952069
32528203248569144408101565113427654841104031612800212712744482882267565001024459
79492598699572856071171904612757173553132382181273765048126001423895987707765069
27829957534314828667970631070936328851607435277381375214109924400404447255812169
82492746902994232350154535685377434765662802828466545354382813840918043139584289
88336738834391431545616247173035244018805312042659762244499199010873290254833701
52203446839354342557449258622312824510234952987857848715978257548695321172080304
88524554360505176199594192656076761115875495
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment