Created
October 10, 2015 12:50
-
-
Save anonymous/83b1f8d2da6ee35d172b to your computer and use it in GitHub Desktop.
A FizzBuzz program. Somehow. I don't know why it works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <gmp.h> | |
char * polynomial="-74101463560860539810482394216134472786413399/404009590666424903383979388988167534591844018460526499864038804741201731572423877094984692537474105135297393596654648304117684895744000000000000000000000*x^99 + 1786563401621773217421750502452955853226339781/1943688752347061390850759947022111850270039951356484879070977067483444756705819339975871373032521468004867185688372878439054154137600000000000000000000*x^98 - 27321291157050372775340569532625689973429185264741/12024094960310264981666053243695462339042976739896622019763059664916718201560234437350734896948634081407660523709959770955883479040000000000000000000000*x^97 + 4936870031754926645682423836151042176171669450909/1336493173680525187613977630110369004256312194947800263402124063124652591386915768177479078216982141485276408003996973457735680000000000000000000000*x^96 - 24473118674386691114350902920738421254018653211816783/5509321860394164940053174453010521117545464714729265530246533637991623460050508333264941533538893049900417192994254190586888192000000000000000000000*x^95 + 70955958411301680398144914423031079100489676862292337/16836637264362473501011399007502441445809569586608960873418948299465063205587292020164507233225819167777166294379724181759590400000000000000000000*x^94 - 195447077296046760793596568618244974213518999474673944569/59491157507055852416187694061463793862473023235358410381001603033824121509104033353924740603723449187054576952025621158952960000000000000000000000*x^93 + 3768626467981309940958736490271243883241827877353984433113/1741377967649783015766545405622297430860918840222558009957633541611339279537692732582026457337185788629435048177571945512960000000000000000000000*x^92 - 191509882478118568856359420149388488822510646896295367474063/155750575988552021285951887210938403754020070181396492816086478255921028728837113970069447115872517740769345923956745437184000000000000000000000*x^91 + 3183866784865674882357102610975198211538996328248908077727/5202263802683857887235775650854684650590202417629062186983081540997395662140923677145844788265223211889820833159315456000000000000000000000*x^90 - 122602932492183703177160295045719667527195624761716927797149793/453818694605338057359999671360543134481410460901504932447804423822613720072369213199503051036924585491752173438102405120000000000000000000000*x^89 + 3267884917053115074211607484324800824218943870251643871272279579/30594518737438520720898854249025379852679356914708197693110410594782947420609160440415936024961208010679921804815892480000000000000000000000*x^88 - 4004044174547674844279788994768854192979024989343859848439957887669/105000388306889003114124867782655103654395552931278534482754929161295075547530638631507492437666865892653491634128142991360000000000000000000*x^87 + 2614176205336312549576169619159093623135554041570840637573065196420171/211207677628799718907722435194995898155393353597399350971058765554329174951929445523147254903352891163383460183591092224000000000000000000000*x^86 - 716006451411473096617305460156561091274738997544995377005310390835921/194912954622369618777890767068102526906047760794942184358673648536664059571732600150560405041853904728113196920995840000000000000000000000*x^85 + 410240697953285420122054060451941934115009832328276826965272801565377/409480997105818526844308334176685980895058320997777698232507664992991721789354201996975640844230892285952094371840000000000000000000000*x^84 - 26212348588395074579354189193145381543990742520514746467309883948644228869/103953575798597130014875075769654681016558805757302498324625945886220831771590720080298882688988749188327038357864448000000000000000000000*x^83 + 220882783236127657162704087892083179311466917563798351138676829228253353623/3757358161395076988489460569987518590959956834601295120167202863357379461623760966757790940565858404397362832211968000000000000000000000*x^82 - 7796870883593381191369924723753019772179483393358980367540108454892001643727/612145813260821422476846186611914709464703333381118012146142996983719405428413800796095894471000178307878281543680000000000000000000000*x^81 + 235122408762538194511446651828345377610256229378338183320696057351775705100488819/91413774780282665756542363867379263280062364451580289813824020882902097877309794252216986907669359960643156710522880000000000000000000000*x^80 - 316906475265395664777796637495189986991838442915753700936550321222454189676348819/652955534144876183975302599052709023429016888939859212955885863449300699123641387515835620769066856861736833646592000000000000000000000*x^79 + 181177909550695919915465252951772792038673797691350011486003300942905943566823/2112256561687837632996479113932814097212527177955530293231862190780167048247617928928355079850892535630135296000000000000000000000*x^78 - 57789433415772634630216031577457555242041539269984260022475408176625247548903228889/4061986715712472203676284696043575554167312681385037838901161651880860131949516367214167282724369173379840737280000000000000000000000*x^77 + 2134535458950793160832196962663876107121474423683264247675195993529254258182090330419/962049485300322364028593743799794210197521424538561593423959338603361610198569665919144882750508488432067543040000000000000000000000*x^76 - 631091698909548007256712103973471958054212535097728236757954024784725738586310094568603/1936512512346455339205943535906682539236301190038911078375969765446766596012604746882407763988120312198742409216000000000000000000000*x^75 + 14538981676528645423344077672908069236869887434837507516385733750765224535413684261900897/322010126574084910810490227809770200010940504397274868971329838392297587229682168638683896387296634288986285670400000000000000000000*x^74 - 3994349313553354841905147261519297950632882977206233059824576426060568758991898168156387111/676034773454280580128201009156612147706366406432502741324944400099659509869265170645885593284141099979290705920000000000000000000000*x^73 + 1934759117203533232128604612670866068960677588544799888197416341916308705050472460059324379/2645928663226147084650493186522943826639398851007838517905848924069117455457006538731450462951628571347517440000000000000000000000*x^72 - 74828703507017155221547336956856069255891791442268302854168619789974250793512639246429798487/873371575016110338510650596527085523264712141064375966072987531034196493427272077012169827608423739810643968000000000000000000000*x^71 + 14395564002250859519168960836932226303920355400699187573040665155286650806220751391843494665821/1513023996154670023053662301025796047345909765505890758126443187566284066078231908063336461913184788686045184000000000000000000000*x^70 - 15329743166115568813283090376253626668040367969445007398914552686365818314278317503761898180010213/15294699091563512189564194999499894826431479151309547881060784396050480233182126896727205538905020146500239360000000000000000000000*x^69 + 26305601258090501879205306471035339509467474092280485581788332881512622061075081580689251496637289/262409053041530846389581776952204077904461652105801066586827183265571964784987471267378526402782208395837440000000000000000000000*x^68 - 10361456188576630221384808158527222229647100677790575331791923574983317291172683548672841228303995183/1087623046511183089035676088853325854324016295204234515986544668163589705470729023767267949433245877084461465600000000000000000000*x^67 + 767797898903469248929199868548542239166505138237379402878179069574788004449666680213341897254733417/891932955971119476001046489136727779501407491556695519096723526458577747638780567301351442868005475713024000000000000000000000*x^66 - 96260544104915617596204329205321677500040832380101225946985187499523441743155830230941627341189422063/1300735560791215902501526129991061345106219258520180965349388476085425881973221660647804187515841318748160000000000000000000000*x^65 + 3049515188107617006899465451510592593850478945444122402802019093220439406338680313222880759924660276887/503510539661115833226397211609443101331439712975553922070731023000810018828343868637859685490003091128320000000000000000000000*x^64 - 60608837871363703935292561032926603396718384608863977962964820831819259334649732909907326338558851794315214257/128384160732765959035983630861473744035597968279052085497143061855802837061815345771931050672838557170025889792000000000000000000000*x^63 + 338836462723427466688159309414849136148268269519904430339639432813060731114127461554557583168950207121001005221/9663323926122168959697692645487271056442857827455533316989262720329245800351692692510939297955590324625604608000000000000000000000*x^62 - 8568076548954153964073949744231454374719016655105066046092875163839125770632652318692032589562754787959826211163/3451187116472203199892033087674025377301020652662690470353308114403302071554175961611049749269853687366287360000000000000000000000*x^61 + 677396887679781760737725179956739248294363705583602337809244194958836282123067068290438393875513500596434033049/4041202712496725058421584411796282643209626056982073150296613717099885329688730634204976287201233825955840000000000000000000000*x^60 - 247331095176495087466532107131267013425834785693933721694737014611158805461040577846734089013424466390806583936529/22910126982450569713915945208603123330393336856372444328595123690027991893741544533665742112133414479986688000000000000000000000*x^59 + 37869984688643580835053714616990169899252664572180383263847650314604381521004416288346419296747859377317803270207/57083278033113788391743565224917807061486366402109200240432034787051811602727401864927408135679552520192000000000000000000000*x^58 - 2506925215550227032322454417892535264802831118963530632476589386239084655434101159459439060161682962857994804258977989/64432750079877188647180549247625974720652736076380759771387659265884732346578554855036811933148294907166720000000000000000000000*x^57 + 218307384967084246971766030092443193123791240180232634963289315139409405975099099155793228510041327448295932861973092943/100228722346475626784503076607418182898793145007703404088825247746931805872455529774501707451564014300037120000000000000000000000*x^56 - 469407976533563613441238140959219853476528496032899936740608284516416031912082252137028640810981457862264277925625687179/4032525855339252622816741857674550798843572597977571359841948743171017262506957174600943331870505531604992000000000000000000000*x^55 + 73699689618693816461227064699911015765797476372254815107269139029574662103067834479313080634902663936636898805228313513/12407771862582315762513051869767848611826377224546373414898303825141591576944483614156748713447709328015360000000000000000000*x^54 - 24612180204694107680717127566096996736401297471736761301992111765154858825416276967227451644420057207333625829630035158605301/85044936308116289288891543024033795693559960559911601114615457468157992266973648105366048473422841019105280000000000000000000000*x^53 + 953150214212367128156958793135968248466324811673809820204649369191227764623619695325614295905083320850372127947793364183439/70792122343049075434704392084378853241032153629227192936694331965725298779389829166508919372993485864960000000000000000000000*x^52 - 25666977644015310408617545775184294351144688963551413795334178809667112044652895563848423782186941023358596167946939402595238031/42912161932289405269219668070348050010335376325648117866997341342423655397243846159904378097640851317456896000000000000000000000*x^51 + 17782513053142522168865081966042232585007922913694757169883151461125774527886048733369277173149195131520624381073319913993401096023/700898644894060286063921245149018150168811146652252591827623241926253038154982820611771508928133904851795968000000000000000000000*x^50 - 10716676277483682102479980422961687749038811014934030093251820734813125273713916971548072564001236765494208025933392945146820788673/10430039358542563780713113767098484377512070634706139759339631576283527353496768163865647454287706917437440000000000000000000000*x^49 + 67644800045321119032561597802632924276221493288989760251222895893646092108772977434192117666304671400028179219076959329227951992537/1702863568741643066238875717077303571838705409747941185198307196127922833223962149202554686414319496724480000000000000000000000*x^48 - 4997580890002144967802648614088114179139989558383840476784830290826564431143597996891085353016261895041917545070156697519664796987/3409140215866517917840240700932591255060991326792632792136913188671149859607330944710942430325306608844800000000000000000000*x^47 + 1422438848649077812928405555139685237598474474616558210776398763524914667696265368960324556645456749031759233086945892952847771889/27552318554955694379096772906244002600169649731621493470934104434303474080878213454021625245085990912000000000000000000000*x^46 - 1835024548246071178140062740140476448668032675616387017170451133124539117343645693606629324914007259470431455987188985825091043732948299/1057795724237615136200832749745011681761868074986665699011836572049374926196710145949625080699727191736320000000000000000000000*x^45 + 3415805155149239991571962453811832359761669088956766361173010114007855593222806538491374272941131028201420443358939024670625318017034379/61432268743359423138118749282662260121055900514413610781632152049970389130118052099844411216871617986560000000000000000000000*x^44 - 1252816937095976599006343236028325812945196927692274425538122485581815675958959457255031707924415664182740560291724211408417504478532484933/737177020224508532902750885287415117754976278614738343729954324242161285775846838146289106627174221217792000000000000000000000*x^43 + 401127199787862140610794180432712903005611545006874118408725116127338965886057844667225798188859689619382811011464518335639516643791158441/8100846376093500361568691047114451843461277786975146634395102464199574568965349869739440732166749683712000000000000000000000*x^42 - 7790660506990038559516797800085085688345929411203081158532622591567764066598426325588815968756964143463335546588761862812134227627365841763/5666750598452939785446933269746389924372472435671977574534514427023076383778268116873965146315832688640000000000000000000000*x^41 + 390374774557465094319555856432694492357311828805618772781391558203622399762035324345806693111023081604976267993609960619493160315887296857499/10737001133910833277688926195308949330389947772852168035960132598570039464000929063550670803545788252160000000000000000000000*x^40 - 9060973473326357599597349367385331699578782168810772026439711473455175849138722451141030848299769502338936655171633851948916688078049179691933167/9898038707809875542453507724722996302086603228750931756050297737649273005382556468847480263633729222606848000000000000000000000*x^39 + 28141851870590520840957194920459124853015997946143648290042931523698853360440807536803936708019565434960633970490751294947136956747007465873974161/1283079091753132014762491742093721742863078196319565227636149706732313167364405468183932626767335269597184000000000000000000000*x^38 - 27853679214693425889480638457081278042829996632540969181598021815144757235302162291694748385634330309571471866769895014951391856607824042860131883/55732199931361911838139120071638492691929072233957949076859784558835996651928808946213289772712439316480000000000000000000000*x^37 + 235783076986806149640733124994230328610650709719303811155024152297922219421945394090038946457017474307753247716219648727122486782952109376372081/21783154165081849457939855412014263315196041521969102629220162031985927946816028511320418124960890880000000000000000000000*x^36 - 827316620313149957662720563081540551903901678645611693281497230758446077940130794472498905395747375775051795032254600589309907499831783878459144167/3715479995424127455875941338109232846128604815597196605123985637255733110128587263080885984847495954432000000000000000000000*x^35 + 312652397690031549504025439744548790275518810671363947159716500741738633051859699773699885172857268287779108373225150450001429521535256038970096493/71912516040466983016953703318243216376682673850268321389496496204949673099262979285436502932532179763200000000000000000000*x^34 - 648235156246722499501889397662416296478623711666711669214386680356106987323639796702586065037718189310585539919927211368937195755032115337186877883977867/8051561258833941200866161002849523491087128154299612455697587000484337891308340117448251206851550217502720000000000000000000000*x^33 + 13698976877437391342090268479207883527107245063147109288703205186810611998978265079419732679882835835308547485157075758717536206600878034993129589657262981/9696503881606466822548494971173619688190950035285554785356233807034901546521871969400044464165307788820480000000000000000000000*x^32 - 40790158494932911167715067112518223702895938612580834906169757435863573047754748612930050831314466491741428731076861440746102414753775823339948650693/1737948961444212662305619178670656372899540807287957368218880179348392901328105413135753083581628416000000000000000000000*x^31 + 11201832087301746720949912216176323690197207889306047218419744444880648311141385653430143867859341580579238126177130936964654904391631898029897285551/30376239426530621087096129070172044410758362916315662602916198663298454935111353611552334588936192000000000000000000000*x^30 - 826425199079499660674886482557022785220611137681669148807911016972876531556535156790255346875578510221574048526857774097076902585327647323910428274371789/150969909949857186802867761478755060721469063694088843136493507356593321027503427449415102907012874240000000000000000000000*x^29 + 7717606558441236915328508452065007501017898748915104378235609532095939529744941613287922792089474238481132464217866303089457369226120820476658116181903707/100646606633238124535245174319170040480979375796059228757662338237728880685002284966276735271341916160000000000000000000000*x^28 - 2797230564976642786900180861312886965354755793441368560443759198703433135501147292507196482517761259967075097612285564462175870529920265635987675435525060897/2763213237676745476103506679486063168591108955728951699094162797048811093101120140263235601072837256806400000000000000000000*x^27 + 10947873113878271427236420661295812301547321094565823740644781436636680158500790770595384735344194230965709156021411952862911197697730699916633081246164248682981/870412169868174824972604604038109898106199321054619785214661281070375494326852844182919214337943735894016000000000000000000000*x^26 - 55136772576506589277029321320893192930784469309074347606902838348095410517113848085794586052482197567054143471739945903577347759628229142070016130593656221769/375436581206079548383628624930171626167270238550129306942141684381631941997434801666200489276200714240000000000000000000000*x^25 + 4261063142478773673605902554004956998839769992430886817601371209799717619879498059960371092033590399474851173389612082483495752020722033742594432935117299211/2648582583464405985069690475697859796594499037390682941390770260187879661357564738385894104241274880000000000000000000000*x^24 - 103279869945264238534226905628295316991532678508845876063214686603858028477519272957932107747733720019105502685280822520512180926025878758797856102304925206683/6257276353434659139727143748836193769454503975835488449035694739693865699957246694436674821270011904000000000000000000000*x^23 + 8687952928463446023448733804255996073283164167391650319188580826518063194969642765014873281647792711395329848400762136952935961819091478507093826389238329649/54888389065216308243220559200317489205741262945925337272242936313104085087344269249444515976052736000000000000000000000*x^22 - 79936346527753405876270392771468459465101475209263625469468727820915893090128697476008122460525158297707915613097715289958073583864369756810577131990543254263/56460712710313650406437814802409917281947392874063823496187395426239879191408818628985895339950080000000000000000000000*x^21 + 1461131990032421486147853771697808281719612299614687875394219963895476069174387862145970429310823818930707458904721947529872393986170834699133824583354600086977/123992153403041742069039907017057073246629568664610749638686044857624832734074268361694515256360960000000000000000000000*x^20 - 312200090643118472670750063506505774870341822548987170894045902101584319225780401083283161688832899720797097690748046533675303435151769292502637599962589286241/3429465512774606913576222825035269049718286085683876686435086240704940810144831946353217346574745600000000000000000000*x^19 + 6777390201945742842668619278493446499062632387379526445868383685374068786276778436339257827630001241213894717779997243204094160191890391436396526551877621/10412918381497115850920313957535600878702737068005669052097865840987689617961931804348776448000000000000000000000*x^18 - 244790992425053979925561934510415929711940276631753453831392456921396395085177774175002081266568598371234027748256929927386574966163323553638605462549106397741/57020360088199594115950820207918135241710285479118943304109006005310514271238191415728573671014400000000000000000000*x^17 + 791627086668915461613937176180706978909224860156807015198926827098379247395210282397824225137580057486909490118163027355882971468352079119094874117996280468301/30410858713706450195173770777556338795578818922196769762191469869498940944660368755055239291207680000000000000000000*x^16 - 201105682895850349970723237645218839737318711309527181527376132039347338197300840330661966557947977315964105233250679709852150315187874222612626696436778464803679/1391505247683575342257150801018048652220120014046017275122661865476262629668235752103791689132408832000000000000000000*x^15 + 7361683814527822671151157900337580966660764592028158758607089476363554669927420245698490951172696947592485738931993376500956195500589869431150481582483829631894397/10065221291577861642326724127363885251058868101599524956720587493611633021266905273550759884724423884800000000000000000*x^14 - 79804100210926416355927152152628263101129791170881685519428678568427389037450548083071162924854019669165295026602230389676128352866739318263324699924619759799/23774615673606060190681037715806607263461045213528734308202445893829443077444504141984977051975680000000000000000*x^13 + 75474188337655173456096375290731912066450586151842796791893535621034551009290103800797916495448391686974832157315185331112773442100213070681968916157285919191/5434197868252813757869951477898653088791096048806567841874844775732444131987315232453709040451584000000000000000*x^12 - 1022163100347194394584296782745704926804054362435079758985740281788374325141878984311410267347311830850990132529482024863222393973922650261135182904628285409977/19863933993416981718499626205818826558491738592691150664853227242721987746746489787201325724650700800000000000000*x^11 + 8010252136561522070305159138491046800744363430065389115467220878545371401006482241855571513458320680062944194518498806345828320496309541560960309094809548119/47295080936707099329761014775759110853551758554026549202031493435052351777967832826669823153930240000000000000*x^10 - 2711365443970966177273911451523988783875904617354285837420752359716691636992189762337568260767947182468601026610163217128763494917155692229692243353568442323/5527143387246127282783578909309943708877378132603499499999315403421792697861716971212009094774784000000000000*x^9 + 12652899392783448054674227893680653883161853159735340370696339169089286880270391046902238650754279846116720594609467362034560558211013968080945309914968721/10235450717122457931080701683907303164587737282599073148146880376707023514558735131874090916249600000000000*x^8 - 3313046647725342518057153115361145207339297033718254547439439700318963521014115696845137191397265110491410135533505751493299031346612618916028914511919/1239605709402070508041622807523302537455224830659030194709604663227247230427387526278298992640000000000*x^7 + 3046565717926194365940323832903231835251359277552624665906185262526359590841369996234648226791500342145014600473447282904932116577035895374212259/625438051545459847244484206461872742134241935165354945412973220328785976865249662599168000000000*x^6 - 413173869320131067011024433441792528417062778730952432981497419812864386315437569024385600088170536939954961534391212412864418315332225631/56483774008700523011581829339961486274053537576976806884295072314410160397769113600000000*x^5 + 4353021818054714966071462648760277711153534016644344923943146869615792271408761430298366331628293793025968463884636790147283786917/496033364224659187070987762864106829927030999109098167982161569347924055040000000*x^4 - 17934197811098234184505120115663766567573276672505192992389452402896782102712277769577690491407663682938300855043475172034999/2228626918501922802407296720467981544473059155918725971419226798581248000000*x^3 + 1303108301384808337973620234796701312222070184700563764341592967729999824895692746034116894896125573186790521/247498906860949796715298301379869660653853847832267818240000*x^2 - 151468218170625212862842711493259019240062636816524589253941649490484680567005204702903861/69720375229712477164533808935312303556800*x + 420738786047480639992166722750192850597637924243"; | |
char ** exploade (char* explodeString, char delimiter){ | |
int count = 1; | |
int prevcount = 1; | |
int position[1024] = {0}; | |
position[0]=-1; | |
int i = 0; | |
for(i = 0; explodeString[i]!=0; ++i){ | |
count += (explodeString[i]==delimiter); | |
position[prevcount]=i; | |
prevcount = count; | |
} | |
position[count]=i; | |
char ** result = malloc(sizeof(char*)*(count+1)); | |
result[count]=NULL; | |
for(int i = 0; i < count; ++i){ | |
result[i] = malloc((position[i+1]-position[i])*sizeof(char)); | |
memcpy(result[i], explodeString+position[i]+1,position[i+1]-position[i]-1); | |
result[i][position[i+1]-position[i]-1] = 0; | |
} | |
return result; | |
} | |
/* I did a typo */ | |
#define explode exploade | |
/* | |
* I am a C programmer. I have a deep and abiding understanding of | |
* NULL-terminated lists and quintuple indirection. | |
*/ | |
char ***** parse (char * string) { | |
char ** adds = explode(polynomial, '+'); | |
int length[3]; | |
for(length[0] = 0; adds[length[0]] != NULL; ++length[0]); | |
char *** addAndSubs = malloc(length[0]*sizeof(char**)); | |
char **** addAndSubsAndMultiplies = malloc(length[0]*sizeof(char***)); | |
char ***** addAndAllOthers = malloc(length[0]*sizeof(char****)); | |
for(int i = 0; adds[i] != NULL; ++i){ | |
addAndSubs[i] = explode(adds[i], '-'); | |
for(length[1] = 0; addAndSubs[i][length[1]] != NULL; ++length[1]); | |
addAndSubsAndMultiplies[i] = malloc(length[1]*sizeof(char**)); | |
addAndAllOthers[i] = malloc(length[1]*sizeof(char***)); | |
for(int j = 0; addAndSubs[i][j] != NULL; ++j){ | |
addAndSubsAndMultiplies[i][j] = explode(addAndSubs[i][j], '*'); | |
for(length[2] = 0; addAndSubsAndMultiplies[i][j][length[2]] != NULL;++length[2]); | |
addAndAllOthers[i][j] = malloc(length[2]*sizeof(char**)); | |
for(int k = 0; addAndSubsAndMultiplies[i][j][k] != NULL; ++k){ | |
char chars[2] = {'/', '^'}; | |
addAndAllOthers[i][j][k] = explode(addAndSubsAndMultiplies[i][j][k], chars[k]); | |
} | |
addAndAllOthers[i][j][length[2]] = NULL; | |
} | |
addAndSubsAndMultiplies[i][length[1]] = NULL; | |
addAndAllOthers[i][length[1]] = NULL; | |
} | |
addAndSubs[length[0]] = NULL; | |
addAndSubsAndMultiplies[length[0]] = NULL; | |
addAndAllOthers[length[0]] = NULL; | |
return addAndAllOthers; | |
} | |
unsigned long long calculatePolynomial(char***** polynom, long int x){ | |
mpq_t finalSolution; | |
mpq_init(finalSolution); | |
for(int II = 0; polynom[II] != NULL; ++II){ | |
for(int Il = 0; polynom[II][Il] != NULL; ++Il){ | |
mpq_t coeff, temp, expon; | |
mpq_init(coeff); | |
mpq_init(expon); | |
mpq_init(temp); | |
mpq_set_str(expon, "1", 25); | |
for(int lI = 0; polynom[II][Il][lI] != NULL; ++lI){ | |
char buf[1024] = {0}; | |
char slash[2] = "/"; | |
for(int ll = 0; polynom[II][Il][lI][ll] != NULL && polynom[II][Il][lI][ll][0] != 0; ++ll){ | |
if(lI == 0){ | |
if(ll == 0) | |
strcpy(buf,polynom[II][Il][lI][ll]); | |
if(ll == 1){ | |
strcat(buf, slash); | |
strcat(buf, polynom[II][Il][lI][ll]); | |
} | |
} | |
if(lI == 1){ | |
unsigned long int n = polynom[II][Il][lI][ll][0] == 'x' ? x : strtol(polynom[II][Il][lI][ll], NULL, 10); | |
if(ll == 0){ | |
mpz_set_ui(mpq_numref(expon),n); | |
} | |
else { | |
mpz_pow_ui(mpq_numref(expon),mpq_numref(expon),n); | |
} | |
} | |
} | |
if(lI == 0) mpq_set_str(coeff, buf, 10); | |
} | |
mpq_mul(temp,coeff,expon); | |
mpq_canonicalize(temp); | |
if(Il == 0){ | |
mpq_add(finalSolution,finalSolution,temp); | |
}else{ | |
mpq_sub(finalSolution,finalSolution,temp); | |
} | |
mpq_clear(expon); | |
mpq_clear(coeff); | |
mpq_clear(temp); | |
} | |
} | |
char someString[128]; | |
mpq_get_str(someString, 10, finalSolution); | |
mpq_clear(finalSolution); | |
unsigned long long returnValue = strtoll(someString, NULL, 10); | |
return returnValue; | |
} | |
int main (int argc, char** argv) { | |
char ***** parsedPolynomial = parse(polynomial); | |
unsigned long long wtf[2] = {0}; | |
for(int i = 1; i <= 100; ++i){ | |
wtf[0] = calculatePolynomial(parsedPolynomial, i); | |
printf("%s\n",wtf); | |
} | |
return 0; | |
} |
Do you do autographs?
This makes me weep with joy
What the fuck am I looking at?
this is terrifying and cursed but part of me very deeply wishes to understand how the hell this works
Similar thing happened to me in D when I coded sleep deprived. I had to rewrite the whole thing in order to optimize it.
LMK if you sell prints of this 😱
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a C programmer, MY EYES!!!!