[Commit] nickle/examples google-puzzle.5c,NONE,1.1

Bart Massey commit at keithp.com
Thu Sep 16 10:53:51 PDT 2004


Committed by: bart

Update of /local/src/CVS/nickle/examples
In directory home.keithp.com:/tmp/cvs-serv21646

Added Files:
	google-puzzle.5c 
Log Message:
Added Google puzzle solution.  Needs to be cleaned up after
Nickle bugs are fixed.



--- NEW FILE: google-puzzle.5c ---
#!/usr/bin/env nickle
# Google recruiting puzzle:
# find the first 10 consecutive digits of e
# that form a prime number
#
# Uses Miller-Rabin to check candidates drawn
# from the first 10K digits of e as printed at
#   http://sources.wikipedia.org/wiki/E_to_10%2C000_places

import String;

string edigits = "2" +	"71828182845904523536028747135266249775724709369995" +	"95749669676277240766303535475945713821785251664274" +	"27466391932003059921817413596629043572900334295260" +	"59563073813232862794349076323382988075319525101901" +	"15738341879307021540891499348841675092447614606680" +	"82264800168477411853742345442437107539077744992069" +	"55170276183860626133138458300075204493382656029760" +	"67371132007093287091274437470472306969772093101416" +	"92836819025515108657463772111252389784425056953696" +	"77078544996996794686445490598793163688923009879312" +	"77361782154249992295763514822082698951936680331825" +	"28869398496465105820939239829488793320362509443117" +	"30123819706841614039701983767932068328237646480429" +	"53118023287825098194558153017567173613320698112509" +	"96181881593041690351598888519345807273866738589422" +	"87922849989208680582574927961048419844436346324496" +	"84875602336248270419786232090021609902353043699418" +	"49146314093431738143640546253152096183690888707016" +	"76839642437814059271456354906130310720851038375051" +	"01157477041718986106873969655212671546889570350354" +	"" +	"02123407849819334321068170121005627880235193033224" +	"74501585390473041995777709350366041699732972508868" +	"76966403555707162268447162560798826517871341951246" +	"65201030592123667719432527867539855894489697096409" +	"75459185695638023637016211204774272283648961342251" +	"64450781824423529486363721417402388934412479635743" +	"70263755294448337998016125492278509257782562092622" +	"64832627793338656648162772516401910590049164499828" +	"93150566047258027786318641551956532442586982946959" +	"30801915298721172556347546396447910145904090586298" +	"49679128740687050489585867174798546677575732056812" +	"88459205413340539220001137863009455606881667400169" +	"84205580403363795376452030402432256613527836951177" +	"88386387443966253224985065499588623428189970773327" +	"61717839280349465014345588970719425863987727547109" +	"62953741521115136835062752602326484728703920764310" +	"05958411661205452970302364725492966693811513732275" +	"36450988890313602057248176585118063036442812314965" +	"50704751025446501172721155519486685080036853228183" +	"15219600373562527944951582841882947876108526398139" +	"" +	"55990067376482922443752871846245780361929819713991" +	"47564488262603903381441823262515097482798777996437" +	"30899703888677822713836057729788241256119071766394" +	"65070633045279546618550966661856647097113444740160" +	"70462621568071748187784437143698821855967095910259" +	"68620023537185887485696522000503117343920732113908" +	"03293634479727355955277349071783793421637012050054" +	"51326383544000186323991490705479778056697853358048" +	"96690629511943247309958765523681285904138324116072" +	"26029983305353708761389396391779574540161372236187" +	"89365260538155841587186925538606164779834025435128" +	"43961294603529133259427949043372990857315802909586" +	"31382683291477116396337092400316894586360606458459" +	"25126994655724839186564209752685082307544254599376" +	"91704197778008536273094171016343490769642372229435" +	"23661255725088147792231519747780605696725380171807" +	"76360346245927877846585065605078084421152969752189" +	"08740196609066518035165017925046195013665854366327" +	"12549639908549144200014574760819302212066024330096" +	"41270489439039717719518069908699860663658323227870" +	"" +	"93765022601492910115171776359446020232493002804018" +	"67723910288097866605651183260043688508817157238669" +	"84224220102495055188169480322100251542649463981287" +	"36776589276881635983124778865201411741109136011649" +	"95076629077943646005851941998560162647907615321038" +	"72755712699251827568798930276176114616254935649590" +	"37980458381823233686120162437365698467037858533052" +	"75833337939907521660692380533698879565137285593883" +	"49989470741618155012539706464817194670834819721448" +	"88987906765037959036696724949925452790337296361626" +	"58976039498576741397359441023744329709355477982629" +	"61459144293645142861715858733974679189757121195618" +	"73857836447584484235555810500256114923915188930994" +	"63428413936080383091662818811503715284967059741625" +	"62823609216807515017772538740256425347087908913729" +	"17228286115159156837252416307722544063378759310598" +	"26760944203261924285317018781772960235413060672136" +	"04600038966109364709514141718577701418060644363681" +	"54644400533160877831431744408119494229755993140118" +	"88683314832802706553833004693290115744147563139997" +	"" +	"22170380461709289457909627166226074071874997535921" +	"27560844147378233032703301682371936480021732857349" +	"35947564334129943024850235732214597843282641421684" +	"87872167336701061509424345698440187331281010794512" +	"72237378861260581656680537143961278887325273738903" +	"92890506865324138062796025930387727697783792868409" +	"32536588073398845721874602100531148335132385004782" +	"71693762180049047955979592905916554705057775143081" +	"75112698985188408718564026035305583737832422924185" +	"62564425502267215598027401261797192804713960068916" +	"38286652770097527670697770364392602243728418408832" +	"51848770472638440379530166905465937461619323840363" +	"89313136432713768884102681121989127522305625675625" +	"47017250863497653672886059667527408686274079128565" +	"76996313789753034660616669804218267724560530660773" +	"89962421834085988207186468262321508028828635974683" +	"96543588566855037731312965879758105012149162076567" +	"69950659715344763470320853215603674828608378656803" +	"07306265763346977429563464371670939719306087696349" +	"53288468336130388294310408002968738691170666661468" +	"" +	"00015121143442256023874474325250769387077775193299" +	"94213727721125884360871583483562696166198057252661" +	"22067975406210620806498829184543953015299820925030" +	"05498257043390553570168653120526495614857249257386" +	"20691740369521353373253166634546658859728665945113" +	"64413703313936721185695539521084584072443238355860" +	"63106806964924851232632699514603596037297253198368" +	"42336390463213671011619282171115028280160448805880" +	"23820319814930963695967358327420249882456849412738" +	"60566491352526706046234450549227581151709314921879" +	"59271800194096886698683703730220047531433818109270" +	"80300172059355305207007060722339994639905713115870" +	"99635777359027196285061146514837526209565346713290" +	"02599439766311454590268589897911583709341937044115" +	"51219201171648805669459381311838437656206278463104" +	"90346293950029458341164824114969758326011800731699" +	"43739350696629571241027323913874175492307186245454" +	"32220395527352952402459038057445028922468862853365" +	"42213815722131163288112052146489805180092024719391" +	"71055539011394331668151582884368760696110250517100" +	"" +	"73927623855533862725535388309606716446623709226468" +	"09671254061869502143176211668140097595281493907222" +	"60111268115310838731761732323526360583817315103459" +	"57365382235349929358228368510078108846343499835184" +	"04451704270189381994243410090575376257767571118090" +	"08816418331920196262341628816652137471732547772778" +	"34887743665188287521566857195063719365653903894493" +	"66421764003121527870222366463635755503565576948886" +	"54950027085392361710550213114741374410613444554419" +	"21013361729962856948991933691847294785807291560885" +	"10396781959429833186480756083679551496636448965592" +	"94818785178403877332624705194505041984774201418394" +	"77312028158868457072905440575106012852580565947030" +	"46836344592652552137008068752009593453607316226118" +	"72817392807462309468536782310609792159936001994623" +	"79934342106878134973469592464697525062469586169091" +	"78573976595199392993995567542714654910456860702099" +	"01260681870498417807917392407194599632306025470790" +	"17745275131868099822847308607665368668555164677029" +	"11336827563107223346726113705490795365834538637196" +	"" +	"23585631261838715677411873852772292259474337378569" +	"55384562468010139057278710165129666367644518724656" +	"53730402443684140814488732957847348490003019477888" +	"02046032466084287535184836495919508288832320652212" +	"81041904480472479492913422849519700226013104300624" +	"10717971502793433263407995960531446053230488528972" +	"91765987601666781193793237245385720960758227717848" +	"33616135826128962261181294559274627671377944875867" +	"53657544861407611931125958512655759734573015333642" +	"63076798544338576171533346232527057200530398828949" +	"90342595662329757824887350292591668258944568946559" +	"92658454762694528780516501720674785417887982276806" +	"53665064191097343452887833862172615626958265447820" +	"56729877564263253215942944180399432170000905426507" +	"63095588465895171709147607437136893319469090981904" +	"50129030709956622662030318264936573369841955577696" +	"37876249188528656866076005660256054457113372868402" +	"05574416030837052312242587223438854123179481388550" +	"07568938112493538631863528708379984569261998179452" +	"33640874295911807474534195514203517261842008455091" +	"" +	"70845682368200897739455842679214273477560879644279" +	"20270831215015640634134161716644806981548376449157" +	"39001212170415478725919989438253649505147713793991" +	"47205219529079396137621107238494290616357604596231" +	"25350606853765142311534966568371511660422079639446" +	"66211632551577290709784731562782775987881364919512" +	"57483328793771571459091064841642678309949723674420" +	"17586226940215940792448054125536043131799269673915" +	"75424192966073123937635421392306178767539587114361" +	"04089409966089471418340698362993675362621545247298" +	"46421375289107988438130609555262272083751862983706" +	"67872244301957937937860721072542772890717328548743" +	"74355781966511716618330881129120245204048682200072" +	"34403502544820283425418788465360259150644527165770" +	"00445210977355858976226554849416217149895323834216" +	"00114062950718490427789258552743035221396835679018" +	"07640604213830730877446017084268827226117718084266" +	"43336517800021719034492342642662922614560043373838" +	"68335555343453004264818473989215627086095650629340" +	"40526494324426144566592129122564889356965500915430" +	"" +	"64261342526684725949143142393988454324863274618428" +	"46655985332312210466259890141712103446084271616619" +	"00125719587079321756969854401339762209674945418540" +	"71184464339469901626983516078489245140589409463952" +	"67807354579700307051163682519487701189764002827648" +	"41416058720618418529718915401968825328930914966534" +	"57535714273184820163846448324990378860690080727093" +	"27673127581966563941148961716832980455139729506687" +	"60474091542042842999354102582911350224169076943166" +	"85742425225090269390348148564513030699251995904363" +	"84028429267412573422447765584177886171737265462085" +	"49829449894678735092958165263207225899236876845701" +	"78230380965678831122893058091405726108658848458731" +	"01658151167533327674887014829167419701512559782572" +	"70740643180860142814902414678047232759768426963393" +	"57735429301867394397163886117642090040686633988568" +	"41681003872389214483176070116684503887212364367043" +	"31409115573328018297798873659091665961240202177855" +	"88548761761619893707943800566633648843650891448055" +	"71039765214696027662583599051987042300179465536789";

autoimport MillerRabin;

while (length(edigits) >= 10) {
    string nextdigits = substr(edigits, 0, 10);
    if (!MillerRabin::composite(atoi(nextdigits), 256)) {
	printf("%s %d\n", nextdigits, atoi(nextdigits,10));
	exit(0);
    }
    edigits = substr(edigits, 10, length(edigits) - 10);
}
printf("no\n");




More information about the Commit mailing list