Jotne, thanks for checking & suggestions:
Yes, awk can goes upto 170 only,
- I have cheked with hp-ux version and linux suse versions too:
With the awk version Factorial:
170! Gives:
168*169*170= 725741561530799404539963...48167424" [ length=307 column long.]
171! Gives: infinity.
168*169*170*171= inf
Scrutinizer, thanks ,awk code works great thanks for making the awk version of factorial, seems there is a limitation of 171th calculation. But it is good to have the code .Thanks,
- For the first unix command based code with sed & bc:
Out of curiosity I tried Jotne's remark for n=1000 value and it worked like a charm .
Also wondered when I put it n=2000, we know factorial of 2000 is going to be huge, and this too worked on Suse 11.2 VM perfectly. It was kind of grabled the display at the 19xx as it was processing so quickly.
---------- Post updated at 06:08 PM ---------- Previous update was at 05:56 PM ----------
All, Out of curiosity I increased factorial value , n=2000 and it worked to:
n=2000;for i in `seq $n`;do printf "`seq $i|xargs|sed 's/ /*/g'`= ";echo "`seq $i|xargs|sed 's/ /*/g'`"| bc;done
Showing factorial of 2000 below :
on Linux Suse 11.2 VM , shell = /bin/bash
GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)
<.......>
represents the range of the display:
2000! =
1*2*3*4*5*6*7*8*9*<.......>1994*1995*1996*1997*1998*1999*2000= 33162750924506332411753933805763240382811172081057803945719354370603\
80779056008224002732308597325922554023529412258341092580848174152937\
96131386633526343688905634058556163940605117252571870647856393544045\
40524395746703767410872297043468415834375243158087753364512748799543\
68592474080324089465615072332506527976557571796715367186893590561128\
15871601717232657156110004214012420433842573712700175883547796899921\
28352899666585340557985490365736635013338655040117201215263548803826\
81521522469209952060315644185654806759464970515522882052348999957264\
50814065536678969532101467622671332026831552205194494461618239275204\
02652972263150257475204829606475092739416585628353177957448287631459\
64503739913273341772636088524900935066216101444597094127078213137325\
63831572302019949914958316470942774473870327985549674298608839376326\
82415247883438746959582925774057453983750158581546813629421794997239\
98135994810165565638760342273129122503847098729096266224619710766059\
31550201895135583165357871492290916779049702247094611937607785165110\
68443225590564873626653037738465039078804952460071254940261456607225\
41363027549136715834060978310749452822174907813477096932415561113398\
28051358600690594619965257310741177081519922564516778571458056602185\
65476095237746301667942248844448579834980154803262082989096585738175\
18886193766928282798884535846398965942139529844652910920091037100461\
49449915828588050761867924946385180879874512891408019340074625920057\
09872957859964365065589561241023101869055606030878362911050560124590\
89983834107993679020520768586691834779065585447001486926569246319333\
37612428097420067172846361939249698628468719993450393889367270487127\
17273456170035486747750910295552395354794110742191330135681954109194\
14627664175421615876252628580898012224438902486771820549594157519917\
01271767571787495861619665931878855141835782092601482071777331735396\
03430496908207058995870138198081303559016076290838857456128821769813\
61824835767392183031184147191339868928423440007792466912097667316514\
33494437473235636572048844478331854941693030124531676232745367879322\
84747382448509228313995250973250597912703104768360148119110222925337\
26976938236700575656124002905760438528529029376064795334581796661238\
39605262549107186663869354766108455046198102084050635827676526589492\
39324951968595417167241932953068367349554400458635983816104305944982\
66275306054235807558941082788804278259510898806354105679179509740177\
80688782869810219010900148352061688883720250310665922068601483649830\
53278208826353655804360568678128416921713304714117631217589577712263\
75847531235172309905498292101346873042058980144180638753826641698977\
04237759406280877253702265426530580862379301422675821187143502918637\
63634030017325181826207603974736959520264263236414544685111342720215\
04583838510101369413130348562219166316238926327658153550112763078250\
59969158824533457435437863683173730673296589355199694458236873508830\
27865770087974988999234355556624068283476378468518384497364887395247\
51032242221105612012958296571913681086938254757641188868793467251912\
46192151144738836269591643672490071653428228152661247800463922544945\
17036372362794075778454209104830546165619062217428698160297332404652\
02019928138548826819510072828697010707375009276664875021747753727423\
51508748246720274170031581122805896178122160747437947510950620938556\
67458125251837668215771280786149925587613235295042234638787895485088\
57644661362903941276659780442020922813379871159008962648789424132104\
54925003566670632909441579372986743421470507213588932019580723064781\
49842952259558901275482397177332572291032576092979073329954505638836\
26404746502450808094691160726320874941439730007041114185955302788273\
57654819182002449697761111346318195282761590964189790958117338627206\
08891043294524497853514701411244214305548608963957837834732532359576\
32914389252883939862562732428627755631404638303891684216331134456363\
09571965978466338551492316196335675355138403425804162919837822266909\
52177015317533873028461084188655413832917195133211789572854166208482\
36828179325129312375215419269702697032994776438233864830088715303734\
05666383868294088487730721762268849023084934661194260180272613802108\
00507821574100605484820134785957810277070778065551277254050167433239\
60662532164150048087724030476119290322101543853531386855384864255707\
90795341176519571188683739880683895792743749683498142923292196309777\
09014393684365533335930782018131299345502420604456334057860696247196\
15056033948995233218004343599672566239271964354028720554750120798543\
31970674797313126813523653744085662263206768837585132782896252333284\
34181297762469707954343600349234315923967476363891211528540665778364\
62139112474470512552263427012395270181270454916480459322481088586746\
00952306793175967755581011679940005249806303763141344412269037034987\
35579991600925924807505248554156826628176081544630830540667741263012\
44418642041083731190931300011544705602777737243780671888997708510567\
27276781247198832857695844217588895160467868204810010047816462358220\
83853248813427083407986848663216272020882330872781908537884546913155\
60217288731219073939652092602291014775270809308653649798585540105774\
50279289814603688431821508637246216967872282169347370599286277112447\
69092090298832016683017027342025976567170986331121634950217126442682\
71196502640542282317596308744753018471940955242634114984695080733900\
80000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000
Not sure how far it can go. Need to try sometime, but this looks amazing calculations by the cpu.