Merge Bram's branch into benchmark branch
commit
abe70e2c25
|
|
@ -58,6 +58,31 @@ elm-stuff
|
|||
# elm-repl generated files
|
||||
repl-temp-*
|
||||
|
||||
# ---> Haskell
|
||||
dist
|
||||
dist-*
|
||||
cabal-dev
|
||||
*.o
|
||||
*.hi
|
||||
*.hie
|
||||
*.chi
|
||||
*.chs.h
|
||||
*.dyn_o
|
||||
*.dyn_hi
|
||||
.hpc
|
||||
.hsenv
|
||||
.cabal-sandbox/
|
||||
cabal.sandbox.config
|
||||
*.prof
|
||||
*.aux
|
||||
*.hp
|
||||
*.eventlog
|
||||
.stack-work/
|
||||
cabal.project.local
|
||||
cabal.project.local~
|
||||
.HTF/
|
||||
.ghc.environment.*
|
||||
|
||||
# ---> MATLAB
|
||||
# Windows default autosave extension
|
||||
*.asv
|
||||
|
|
@ -253,6 +278,64 @@ cython_debug/
|
|||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# ---> Ruby
|
||||
*.gem
|
||||
*.rbc
|
||||
/.config
|
||||
/coverage/
|
||||
/InstalledFiles
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/spec/examples.txt
|
||||
/test/tmp/
|
||||
/test/version_tmp/
|
||||
/tmp/
|
||||
|
||||
# Used by dotenv library to load environment variables.
|
||||
# .env
|
||||
|
||||
# Ignore Byebug command history file.
|
||||
.byebug_history
|
||||
|
||||
## Specific to RubyMotion:
|
||||
.dat*
|
||||
.repl_history
|
||||
build/
|
||||
*.bridgesupport
|
||||
build-iPhoneOS/
|
||||
build-iPhoneSimulator/
|
||||
|
||||
## Specific to RubyMotion (use of CocoaPods):
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# vendor/Pods/
|
||||
|
||||
## Documentation cache and generated files:
|
||||
/.yardoc/
|
||||
/_yardoc/
|
||||
/doc/
|
||||
/rdoc/
|
||||
|
||||
## Environment normalization:
|
||||
/.bundle/
|
||||
/vendor/bundle
|
||||
/lib/bundler/man/
|
||||
|
||||
# for a library or gem, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# Gemfile.lock
|
||||
# .ruby-version
|
||||
# .ruby-gemset
|
||||
|
||||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
||||
.rvmrc
|
||||
|
||||
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
||||
# .rubocop-https?--*
|
||||
|
||||
# ---> Rust
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
|
|
|
|||
|
|
@ -0,0 +1,201 @@
|
|||
2233643232222242333443433223122333324326451323323334325223136631334332233233323164354342233332238233
|
||||
6436547659356357277564683346658554864789866767856546426667566576537557576764753366663247799566575359
|
||||
4322212422212222222222112222221252322222222222121152214312222222226122122421262632221222352222223522
|
||||
5242873574376258254526262841222235756126125363535226724625252231422222223232432416114933476433226425
|
||||
4423241233122222212222152223222321224343432221222131223143222222223442622361254132221212223321223232
|
||||
2354443335444444444445473233436443443447434343453464372444444744444341435444543443433645644446664444
|
||||
7344773375355374532433311243433365663564579278356438583444355566467535626553263862265655437577558445
|
||||
2422122121212324322412122634143132116824441421223222862232324232233322227221224221222232422452322422
|
||||
2335425524341553453213523155345249534445348244223423324254265524132552444254422523422425353142334556
|
||||
2543542334354463443444631655434665743432434343442354554443244445263434575354472655455354443554334453
|
||||
2533222231331423136323422331324323122212222133234123324923235534153325322253223223121312212332233222
|
||||
3655636344614544753471372637363622461657323523555373676516477617243136625537745875577456765251534745
|
||||
8347857486272332654345885359345864556245456476353536374444758537485854624467575625455471966355365444
|
||||
2333131222324323323333122331322333223232233313232332423233313334321321324232231322333313332323233322
|
||||
4333455333232133222434323424423223782622224423233533223343333237344243134333437453254322633363332442
|
||||
3333224546432265536343345623343413494323264462333222332725333245323343134323244336443544223233233344
|
||||
1122222222422322432314212522412222221222221222213224222532253232222211212243222222112122242232335222
|
||||
6223222222211527224244221412234422422713221226223222321153222234233432222213222222222222222324231636
|
||||
5522284428622511162523222215246221521122222226162118422222222122212222225432222224262224422471367526
|
||||
5956484444745474342547425434594374468434864864145434543435444445445435447847779785545443385653654957
|
||||
3142333733311646312333123413312243223323322322513332472235234224324411362463132422246321332342334253
|
||||
2492222222662312432222234253224154223124222422222213353722442234192272247469222421222262223267156265
|
||||
1222322226313332322222322222252325331322122133223322232222712222224726531252321222222231322222222233
|
||||
4438912132222624231242322622336222122622235321223232221222212122524232224232242223126113262212212435
|
||||
4342543122243322234244522425514322434334515225622212522435254747435834212524224434345847214233232221
|
||||
2232662535536423636216213652233222333323333326232362322345211258324623265442343221333714253323275637
|
||||
2692334323322554444433246235632624244563226221655324344313452376684265724434633442434233553662233643
|
||||
1644224326534722127241464425124252623243373421327743244224241335526234247333375133245132323342647346
|
||||
5333657533435533437765632361628578858239468476298973236397242266676766654544552648636554686924674746
|
||||
4251343354552554445476666443753334477733455252244352372543524364954246663435527633554214534575345543
|
||||
3245444253442524962129783345453352426254163846525128886263548552344445395534373553663544462243475363
|
||||
2142532422249222122122222121162472244223312421312253332722222114213222352432221242221233181232122212
|
||||
4566465546696559368565756646438955545369947544855754656465452555756544447765644457465366557485337369
|
||||
1772653222555582242247246232214292222697233222223253514255232252129642112322335241212183231264525284
|
||||
4354354427322426542444547537346731353311444756444523378323634345432344556435433536444746445434454453
|
||||
5344542553344445244734444454543444343844354445344455544437343413454472243534445445435545543335434544
|
||||
2421234244222324252243122112531222432451151212536641122423232254323625642217243224625513637522242233
|
||||
2444236443231233244646213453222422433135223422213222112323142221124322223132322364143222422234525135
|
||||
3993952352239334636476372777272353823836333556663343425385311323219418661163732333739633435335233629
|
||||
2335132452334122223322212232323222332121214232343232321253615232234232222225124143231423232421221232
|
||||
3435253533345115535125331555355212454321233141243323222231511511242334253123412222244355444111336789
|
||||
4342262562424446414642344324642513444741415543524724444347445424742344243227544243834261383344344433
|
||||
5133269339551412322324214425133339363433753643223332253433334733423351353332323252563825324213546533
|
||||
3365372336245325375435335434332645526446285234343523632282522323636232643244678477432531362385446246
|
||||
2311131324212395342286212542325322246532472361652435616622122663643522122343832326532338222232323482
|
||||
7765353451358575733572283573547384566323256675564262642584334376524365537964746444124713224735546774
|
||||
2252222525225522412122213464272135235332236223312272922282292361721421642435252222222226223782322215
|
||||
2134223233222221422122222223312222321222423333322222233223223232122322211216211222321222223242222422
|
||||
2222361132122134212316842523222722221729212242142646822267221232222222222412222222522222242753222222
|
||||
5337864557478543434125566533466435547454453457543754463395635497321323245554355354848544555244335554
|
||||
4466625524532724322343146236829413367515473225463633637657254355393224314422246746538323136326741268
|
||||
2322233123334342233531132214322222423222332332324712223135133223235235532233233332322352216243433223
|
||||
3633623322235342316346231131633361331265333443339233365455623337353332167234337236515462224252333216
|
||||
3322584324332533632225363333332331626133332232223132322321336323322334213633233333215232333442313275
|
||||
5965751122343223845246255553658564621769664976957663344222229522752322289731722915285462282698823463
|
||||
3121123533222322223221263122523242222123232221232342322162223241233222314224211222222122122322232212
|
||||
6122331319122223262333221232321143613412232222221213242132321221322221332342352322122226512222222633
|
||||
5145245555235222232228435425532224121513422242326222356224253225455252412222754222322432125224161442
|
||||
3132322122223332322332242224222322222422352533113232233223232223222341222123253242213213224323354225
|
||||
3252413233224241123451142223232242212442241222231545322234225222422473143343222322424222122252122416
|
||||
1222222432232632232221222223222122521241321222251212132222211232332222334222222232224222322222222133
|
||||
2133325423225322332222532333232222323233222322122152432122332224212222222222212323324323322362632221
|
||||
4122341242242411343233341124424221223432443244144143434244411231333334322314223334222434334414256789
|
||||
2222212542623221122371215317524472552543532242222229542515225421552216216324337665122323271821561222
|
||||
2122122122122422123242223132212211232222223222228423241243212222232242216422232232113122122222232222
|
||||
2342451233212332332223232222123322212234372232433123322242422233233221221324231233221221232222235312
|
||||
1531224333222562318222324631131222342272182322522822182242335222241223334222527222212244253473221323
|
||||
2222233222142234223233121222223122242221213223222122332242431122213321122214222212223322224222223312
|
||||
2222222143243227332452232222322322321323613266223112234422442212224233243242223133522611232111122321
|
||||
5654553447313533554553893854763333467444552579533944455663535653524659436665547645355435546543554545
|
||||
5323331522211233252524233313212132234222532343133332653523335426323323143321221322323323221347322323
|
||||
3344255554553462322384556525546538353335583545124321555537334342254324532523646534635433532353543335
|
||||
2252335254447422332431226227992713322234315316472133442221225414241542213654242426442132142182572344
|
||||
3135523223226233323223323223222544253222122262342343232237222425282315212232123222235333112312222334
|
||||
3354773326663365346493365244732433363452542643435334753354577776335434754556592544964263743422332443
|
||||
6371439222222352424162472287212322327622532242273512222352621682699762212223226214132243222323527222
|
||||
2232543232222452352224332423252323532333242233144332224232233325233442123233222442332344242445234243
|
||||
6425615474554454141541665641252716724411315412715646331276275654347342167232742714674637136141217389
|
||||
3235333323334334433422362433341233323333231333336463133333453437363325442333342333823233363633333354
|
||||
5765262746346263664544526674676762456349723566665876664674156663555573556676764444715554476437677855
|
||||
7423434333422334442444334422343286432323333344344314233133333443444333838532343434543341233343232733
|
||||
6774788365875695878887443545568759778677247747655763848548555778646627725586786843876788675548758494
|
||||
3262313215125212725325312211423222332227433222263225122322254423222211222422352233312213443215423525
|
||||
6142243652443244444342244442113325153442421335264515232174224223431316224224433264315222264244474425
|
||||
2921833253133742442324622132642228232344243922221222431224543231122332332233333123362234243552323522
|
||||
5632565666566658566466565564426236675643353576665434456559645576553857764724552526336855216775546576
|
||||
2532452536565234455556555433545333343535235259355533573737535333495454353444323553254555558327634454
|
||||
5548929366483365659354448563354373455759474784978453866356866476356667554667454666687754395646666584
|
||||
2422224232218244232132234324422124322122422432233246415332224232332414212225332241243325223322222222
|
||||
3758934793272332176257536845332333423543533433543322226223463523347666464677433843442824654415933924
|
||||
2622232121212222232322152424125221342152122221224222323442222231221231265222424444243222225322221222
|
||||
6214422421342323434331423232234143232134222323441334231133223132222426213232335122424533433312424333
|
||||
5495352464253923643432324472475257423635544644337693443224359353932343696565533473655334633335357234
|
||||
7254749566545484267477472424253562668987384296476363553384653423843774734634364663792242324756555646
|
||||
6226324333333271442443546421325232432323192149222232363654233652232253322232543523855788643345523533
|
||||
6423316551511466142352352513435356146435255444345656413213453213333153116125465222652164154334412789
|
||||
3233343444252424634655344331632462565545324335341334523524342535241225553354334625422632545362561363
|
||||
3445525556368253862333435337455253455524557517455232345255743265518361673494731765233544323823734449
|
||||
8544272422454343423222253523841223262532426642832273222113352334442513324141234434252431222216421154
|
||||
5423334354644265263636536355524642453634246642522263635654356321443365454125632234324233624247276342
|
||||
6443545413135523533265443323245434225234223442514335322555552333234542252323354441535625432213233475
|
||||
3212212222223312122122125221321232213221322313122221312222226222222122212222222922221223212132141212
|
||||
2323212122324611722242222244224112222243222123241262221222362413421211233222242222215222124222122331
|
||||
5844366354463476656352455342626163223651573323322732274227653444734256235242233221366322344236655364
|
||||
2625454454614434442613618224132466334432732446343621534141835624243221346614444345314364443148234344
|
||||
2323222223223124321322321223214122333222332222231313222222332322222522333223222122132323212343223223
|
||||
4437368344416381611321431224542447234422632416425742323247454382441741433122653324364923229242444543
|
||||
1246633747466243525472445465264464613362434426572366643424314563444534564662442453243348442543252552
|
||||
8455213554255167364635127532563534225444445625337655356663242455242553536364567566362637563621552464
|
||||
1145243234422322531234121131315342152533253745423235234129642243232433334524273522215353252222256345
|
||||
2222221322232522222222232222223222212222223212222232222112321222123213222222242121522231322322222222
|
||||
5554324763412143342413244121235412334563414442244613543522434445264434234433442544443434242225336524
|
||||
3212234222234342422134323321353344221222241463622421223322332224422435432352244231322324233321242222
|
||||
1738535622754134632333123483712322334123243222775212333324326533722431671361323312322346241332334322
|
||||
4351132523543724323443552656312222233223234323221255492443514427243424322442435353343365537374457525
|
||||
2226222122222222222211222321222222362222222222262221222222222462222242422221222112213252923212222227
|
||||
7372265262132122222222222282647132453212233322331232223212732224333228225333323211212536423333531243
|
||||
3342577332235352233233553852633532263644351255533142324433446226235457211213535744631435423223364363
|
||||
8446255244282932322534869773258925347844614356985425432837381986388785453532534245572534443192852357
|
||||
5446735236335373623324345623337331834844472537246434774964444227448844322344333544544434382344464148
|
||||
4433323344453244323434533223334334444433433643133631233655333413335732264332842324635343324544539433
|
||||
6344376432398243372333532336643528844236533248338383473645366575356475384433935577645374443832252963
|
||||
3443222635222221244334227234322246222342227224235242323213273234134421523235225245425122222255224231
|
||||
6585657577798869776763766747566877567766997677734495477637554466647747676466367736757977637777676777
|
||||
3242552333334223333252225333433565333333465343535354235233123752242314432223435333332233333332223332
|
||||
1311222262211312324225221221345121353311223322212222241343223322112224651422143221323251213224222225
|
||||
5533566445555425555535555545655564353354655435445566346633555555464665566547564434755465554654365665
|
||||
3463363433672383135556336377441633635538123755433353487535473513268444423364361656537543324433363331
|
||||
2222122334223322241131242133321225242732213242326212422232444422322212222223342231223222322222422213
|
||||
4323633242332312332424232178525522242552333523216333423225215442333672335222322723212232753241221533
|
||||
4362565458455443433534444665335234724445746564455242246332242464545442435623423325344343664843444243
|
||||
2223437712828555541728813515663367733828286734326188656173257638346432837355155675314858434277276319
|
||||
5244262352623221152324113352242726453823552433244642443115222322322662622123452436542542126162944562
|
||||
2222362523222242322324333353323221232222533231223413323541411332323322544333232433153322333233223142
|
||||
2225312222212215222122212322213222513122221422323222322225262221222251222457222112222121342121222221
|
||||
4313232231424332229233454343224319396724123323633382235223632236322391443232222332212432283863439233
|
||||
5213575451225235425253533432213743534342624252124435242432121345254352522422122212553341253217252322
|
||||
2123412112522432522412192122226522121425425222252222522512262432222222411232122222423341231351232221
|
||||
5465625548366424522551965584434936726545472565217598582254364534384215551343672449253467655554836446
|
||||
7254422422222617225423523253332238633333432123322237324623122462125452782322233252232462154221236133
|
||||
6535353554552342214454325582546583245579544353448348251572751295756482557556245336852375322477534475
|
||||
4322124613433135333247343244442342123263246432131544439324486672223437344234314333231434329452334422
|
||||
3222122222211221222442221522222323121122254222222212221122222222212132223211142223221222122232253223
|
||||
4522264542561523248146564185215223352222363522622331425472532241114233344524356242234315554712254611
|
||||
4524553354655655655852774652636663566555536557376256434754354524655756453536565466492456544475546375
|
||||
6482342921224824333643274834413223286723233143344312632422114943523238322122443642964332282223862242
|
||||
2222532222225126242562235312251241241152363142662511122221241252422235424523144132221224242525432316
|
||||
3352233122122222414623322422421412265422222322631132532211362245214223424432222632322122452236232543
|
||||
7435435245443454483642323432454553456537424534753454323445333535524536533132553244725534224634223674
|
||||
4442455534524835435555455546253515474453446464546545554444443534453544443464344544455454444445545656
|
||||
6318372235932344212322623432143332348233334233234531434374327935349323133422333672232723333333333313
|
||||
2343437112323223553423322434332234373285822222438334742444737123322352633236431422342337553563236343
|
||||
2534525223332122254212422543221212222333444234231612225123231222134222224211232431442153233222232235
|
||||
3311333353223232533542243332322443233333433334433333333334343333233225332233334323333332233323334534
|
||||
3728642494543682323613638224245843442324642214465451312451322235317994852247254439532312342435223415
|
||||
2644444442446656433255324244844744224332444644642423633224344444334435346443263334422284244442354422
|
||||
2132343337743333341331172224332353222832422333133333324323434332423323223323333123532233221521332232
|
||||
6456746544533347353533424453434256445454442444545332474441436424325427632384444467424543463243246273
|
||||
3133424321432223332224512124224222232131232222432232433224233324222323231122133222444342422223422412
|
||||
2951222223232342212324221372233422121222222122428412742122222272113231225115272231252232221122231342
|
||||
4332522234422363462322222143321322323545222323433222352435311251238232125232422442222133116432133222
|
||||
7666998669668693896756755965999793569795865899869698558598997759886859928589579967584996689695478789
|
||||
4352363453212525423622255562341442344215444134321422542354722245343422441244464243637481135554112362
|
||||
3223443344545244343434584554333453154433434434333249442265443244333635455338332244343243311134334424
|
||||
1665322162231323425324323123442341125222233315531323536111322442242235242132414112244264232443422245
|
||||
2414221222221172231122222143244322162212222222425232121223222222221222422345212226312222112112221232
|
||||
3331333314633233122533233233233112324313222231331243321234122333341411343323323432121313333225221232
|
||||
2642724252231252242432324542254325124442563345455242145355324151614235225515342253523532421213493425
|
||||
6315423423623323244234343366465111333233473411272233343328223323662414442233633141132225735345273323
|
||||
2255222422222341222222221221242522222412222122121222222221222225322225221312112222122422222222221252
|
||||
3221262222222452233122222424222222221221233427232242322221283223253322122222222222221211222222222322
|
||||
3563473466663465624422525832655214646265347424423434534754575561344661544144721234545452426624325665
|
||||
1512522452333543222325524385269535432435333245472553438445343544134325483212359524535452434233544546
|
||||
1242352442411351533231323433123333232332131522241133232223323312221332252133231231222521342332233113
|
||||
6796977884635885678886386887784686985966565558559785568975267889586689776858777746657576899885687867
|
||||
1322221211222232222222212224341222212122652423212122232222221622222212122222264522211212112222222222
|
||||
2221122242132222242321653225213222212212123122122225216212241422222121335224252128222312122223152213
|
||||
2222485454314145422676223532428253544275212444246273219543235423266271388223486621383423434123322786
|
||||
9264342243354532322432433325652333233452313535423525423336263384434513334133343152333512233333211423
|
||||
2221254122222222483253222232224232221212127215222224142222112222222222312552242222122224121422222211
|
||||
1234422452224434224462441231223422424234232233163423323463242243214153522224424343443144243233321226
|
||||
2322212322222232222122222111221213222232122222212222222212222322321212111322222122221222222212221221
|
||||
3434526563345631541253456353554355344534635445555335344434585646443364555465443732452735555413335455
|
||||
3225312137123114121262224262133222252322222211222221322324232222112222621222224422222232222221266238
|
||||
2353522543223422534146562225414223172345423224513313523223255542242224543225213372456442522442223274
|
||||
2321822523345672525222333345331141642241339237232233346584343212323556147252622534732253132335723124
|
||||
2221142243241323222232423422323251235242422122522224222322222325214214222222234332641212512222222223
|
||||
5352353234444335353333325633455343325334323243442544543453525334742134535534164234322442365546552443
|
||||
1644535454544465443444444444356555544434446443634464664335484454462433434354444442444466442444522245
|
||||
6433454454447444425444475352634433345446225436132754337645216743354253676545324347755544565443915533
|
||||
3467493473794344524434814455434343541545634344354934325134523344486353664347445446466468352473724335
|
||||
6583456635588454567555367246548474858674467585559584465654664563665845468923825636652445446833546865
|
||||
5444533574534446655337755343315552455447755452563434858445835538545235556545555373594853555475534542
|
||||
3441235133213337324673253262369232322322523734393339321333332333338374353323483332652333273343333334
|
||||
2422443223431842223321234271323322427434181322342241645342244245114331332453823332343424413141233222
|
||||
3324243325325223334126334234442422148382225223733442252241413434444155241324232233814134662324642534
|
||||
4426433352444223343443233364226332215123531534353433343449744443257223333742332354436544443343235466
|
||||
1311262322731223323222364222211222212331291223331233416323222221212322331423211242312141133222213123
|
||||
2231221213222221212231221334133642822242221322242121224231222213322222222222223213122225213222251122
|
||||
2222462325135343335552659427182617224656226146173226235225282512237335226552631126273541364136347217
|
||||
|
||||
|
|
@ -30,14 +30,6 @@ pub fn answer(text : String) ->( u16, u16 ) {
|
|||
( clicks, passing_clicks )
|
||||
}
|
||||
|
||||
fn count_passing_clicks(old : i16, new : i16) -> u16 {
|
||||
if old < new {
|
||||
(new.div_euclid(100) - old.div_euclid(100)).abs() as u16
|
||||
} else {
|
||||
((new - 1).div_euclid(100) - (old - 1).div_euclid(100)).abs() as u16
|
||||
}
|
||||
}
|
||||
|
||||
fn str_to_dir(s : &str) -> Option<i16> {
|
||||
if s.len() < 2 {
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -1,50 +1,189 @@
|
|||
use crate::utils;
|
||||
use std::ops::RangeInclusive;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn answer(text : String) -> ( u64, u64 ) {
|
||||
( text.split(",").flat_map(to_range).filter(|x| is_invalid_by(x, 2)).sum()
|
||||
, text.split(",").flat_map(to_range).filter(is_invalid).sum()
|
||||
)
|
||||
use crate::utils;
|
||||
|
||||
pub fn answer(text : String) -> ( u128, u128 ) {
|
||||
text.trim()
|
||||
.split(",")
|
||||
.flat_map(Range::from)
|
||||
.map(|range| range.invalid_id_sum())
|
||||
.fold((0, 0), |(x1, y1), (x2, y2)| (x1 + x2, y1 + y2))
|
||||
}
|
||||
|
||||
fn is_invalid(n : &u64) -> bool {
|
||||
for b in 2..=10 {
|
||||
if is_invalid_by(n, b) {
|
||||
return true;
|
||||
struct Range {
|
||||
low : String,
|
||||
high : String,
|
||||
}
|
||||
impl Range {
|
||||
fn from(s : &str) -> Vec<Range> {
|
||||
let mut ranges : Vec<Range> = Vec::new();
|
||||
|
||||
let (low, high) = match s.split_once("-") {
|
||||
Some(pair) => pair,
|
||||
None => return Vec::new(),
|
||||
};
|
||||
|
||||
// Sanitize input - for AoC, optional
|
||||
if low.len() > high.len() { return Vec::new() }
|
||||
if low.bytes().any(|c| c < b'0' || c > b'9') { return Vec::new() }
|
||||
if high.bytes().any(|c| c < b'0' || c > b'9') { return Vec::new() }
|
||||
|
||||
for size in low.len()..=high.len() {
|
||||
let range = Range::new(
|
||||
if low.len() == size {
|
||||
String::from(low)
|
||||
} else {
|
||||
std::iter::once('1')
|
||||
.chain(std::iter::repeat('0').take(size - 1))
|
||||
.collect()
|
||||
},
|
||||
if high.len() == size {
|
||||
String::from(high)
|
||||
} else {
|
||||
std::iter::repeat('9').take(size).collect()
|
||||
},
|
||||
);
|
||||
|
||||
ranges.push(range);
|
||||
}
|
||||
|
||||
ranges
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
fn has_pattern(&self, s : &str) -> bool {
|
||||
assert!(s.len() > 0);
|
||||
assert!(s.len() < self.len());
|
||||
assert_eq!(self.len() % s.len(), 0);
|
||||
|
||||
fn is_invalid_by(n : &u64, by : usize) -> bool {
|
||||
let s : String = n.to_string();
|
||||
let size : usize = s.len() / by;
|
||||
for (l, c) in self.low.chars().zip(s.chars().cycle()) {
|
||||
if l < c {
|
||||
break;
|
||||
} else if l > c {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if s.len() % by == 0 {
|
||||
for i in 1..by {
|
||||
if s[0..size] != s[i * size..(i + 1) * size] {
|
||||
for (h, c) in self.high.chars().zip(s.chars().cycle()) {
|
||||
if c < h {
|
||||
break;
|
||||
} else if c > h {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
fn invalid_id_sum(&self) -> ( u128, u128 ) {
|
||||
// Part 1
|
||||
( if self.len() % 2 == 0 {
|
||||
self.total_of_pattern_size(self.len() / 2)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
// Part 2
|
||||
, self.pattern_hashmap().values().sum()
|
||||
)
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.low.len()
|
||||
}
|
||||
|
||||
fn new(low : String, high : String) -> Range {
|
||||
// Verify they're the same length
|
||||
assert_eq!(low.len(), high.len());
|
||||
|
||||
// Verify they're all 0-9
|
||||
assert!(low.chars().all(|c| '0' <= c && c <= '9'));
|
||||
assert!(high.chars().all(|c| '0' <= c && c <= '9'));
|
||||
|
||||
// Verify they're in order
|
||||
for (l, h) in low.chars().zip(high.chars()) {
|
||||
assert!(l <= h);
|
||||
|
||||
if l < h {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Range{ low : low, high : high }
|
||||
}
|
||||
|
||||
// Create a HashMap that counts the number of patterns for each value
|
||||
fn pattern_hashmap(&self) -> HashMap<usize, u128> {
|
||||
let mut h : HashMap<usize, u128> = HashMap::new();
|
||||
|
||||
// Populate the HashMap
|
||||
for size in 1..=(self.len() / 2) {
|
||||
if self.len() % size == 0 {
|
||||
let mut patterns : u128 = self.total_of_pattern_size(size);
|
||||
|
||||
// We'll double count a few patterns.
|
||||
// For example,
|
||||
//
|
||||
// 247247 247247
|
||||
// |------|------|
|
||||
//
|
||||
// this number is a pattern of 6, but it is also a pattern of 3! (lol)
|
||||
// 6-patterns always catch ALL 3-patterns. In fact, all
|
||||
// k-patterns are always caught by n-patterns iff k | n.
|
||||
// Therefore, if we want to accurately count the number of
|
||||
// 6-patterns that AREN'T already counted as 1-patterns,
|
||||
// 2-patterns or 3-patterns, we must subtract our total by
|
||||
// those amounts.
|
||||
for (key, value) in h.iter() {
|
||||
|
||||
if size % key == 0 {
|
||||
patterns -= value;
|
||||
}
|
||||
}
|
||||
|
||||
h.insert(size, patterns);
|
||||
}
|
||||
}
|
||||
|
||||
h
|
||||
}
|
||||
|
||||
// Count all invalid IDs where the pattern is of a given size.
|
||||
// Then count the numbers of those chunks.
|
||||
// These can then be re-used to count the full value efficiently.
|
||||
fn total_of_pattern_size(&self, size : usize) -> u128 {
|
||||
// 1. Find the range of all patterns of size `size`
|
||||
let inf_str: &str = self.low.get(0..size).unwrap();
|
||||
let sup_str: &str = self.high.get(0..size).unwrap();
|
||||
|
||||
let inf : u128 = if self.has_pattern(inf_str) {
|
||||
utils::str_to_u128(inf_str).unwrap()
|
||||
} else {
|
||||
utils::str_to_u128(inf_str).unwrap() + 1
|
||||
};
|
||||
let sup : u128 = if self.has_pattern(sup_str) {
|
||||
utils::str_to_u128(sup_str).unwrap()
|
||||
} else {
|
||||
utils::str_to_u128(sup_str).unwrap() - 1
|
||||
};
|
||||
|
||||
// No patterns exist!
|
||||
if inf > sup {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 2. Calculate the sum of the pattern snippets
|
||||
let pattern_sum : u128 = ((sup - inf + 1) * (inf + sup)) / 2;
|
||||
|
||||
// 3. Calculate the sum of the patterns when they repeat themselves.
|
||||
// For example:
|
||||
// Step 2 calculated the sum of x = 123 + 124 + 125
|
||||
// Step 3 calculates the sum of
|
||||
// y = 123123123 + 124124124 + 125125125
|
||||
// by realizing that:
|
||||
// y = 1001001 * (123 + 124 + 125) = 100100100 * x
|
||||
// = (10^6 + 10^3 + 10^0) * x
|
||||
let layers : usize = self.len() / size;
|
||||
let factor : u128 = (0..layers).map(|layer| 10u128.pow((size * layer) as u32)).sum();
|
||||
|
||||
factor * pattern_sum
|
||||
}
|
||||
}
|
||||
|
||||
fn to_range(s : &str) -> RangeInclusive<u64> {
|
||||
let empty = 1..=0;
|
||||
if let Some((low, high)) = s.split_once("-") {
|
||||
match ( utils::str_to_u64(low), utils::str_to_u64(high) ) {
|
||||
( Some(l), Some(h) ) =>
|
||||
l..=h,
|
||||
_ =>
|
||||
// Empty iterator
|
||||
empty,
|
||||
}
|
||||
} else {
|
||||
empty
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
use crate::utils;
|
||||
|
||||
pub fn answer(text : String) -> ( u64, u64 ) {
|
||||
text.as_str()
|
||||
.split_whitespace()
|
||||
.map(|s|
|
||||
( BatteryBank::from(s, 2), BatteryBank::from(s, 12) )
|
||||
)
|
||||
.fold((0, 0), |(t1, t2), (b1, b2)| (t1 + b1, t2 + b2))
|
||||
}
|
||||
|
||||
struct BatteryBank {
|
||||
digits : Vec<u8>,
|
||||
size : usize,
|
||||
}
|
||||
impl BatteryBank {
|
||||
fn add_battery(&mut self, b : u8, min_pos : usize) {
|
||||
for i in min_pos..self.size {
|
||||
match self.digits.get(i) {
|
||||
Some(x) =>
|
||||
if b > *x {
|
||||
self.digits.truncate(i);
|
||||
self.digits.push(b);
|
||||
return;
|
||||
},
|
||||
None => {
|
||||
self.digits.push(b);
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from(s : &str, size : usize) -> u64 {
|
||||
let mut bank = BatteryBank { digits : Vec::new(), size : size };
|
||||
let l : usize = s.len();
|
||||
|
||||
for (i, n) in s.chars().filter_map(utils::char_to_u8).enumerate() {
|
||||
let offset : usize = l - i;
|
||||
bank.add_battery(n, if offset > size { 0 } else { size - offset });
|
||||
}
|
||||
|
||||
bank.measure_joltage().unwrap()
|
||||
}
|
||||
|
||||
fn measure_joltage(&self) -> Option<u64> {
|
||||
let mut joltage : u64 = 0;
|
||||
|
||||
for i in 0..self.size {
|
||||
let n : &u8 = self.digits.get(i)?;
|
||||
joltage = 10 * joltage + (*n as u64);
|
||||
}
|
||||
|
||||
Some(joltage)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
use crate::utils;
|
||||
|
||||
pub fn answer(text : String) -> ( u32, u32 ) {
|
||||
( 0, 0 )
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
mod day_01;
|
||||
mod day_02;
|
||||
// mod day_03;
|
||||
// mod day_04;
|
||||
mod day_03;
|
||||
mod day_04;
|
||||
// mod day_05;
|
||||
// mod day_06;
|
||||
// mod day_07;
|
||||
|
|
@ -33,19 +33,19 @@ pub fn day_02() -> DailyOutput {
|
|||
( p1 as u128, p2 as u128, d )
|
||||
}
|
||||
|
||||
// pub fn day_03() -> DailyOutput {
|
||||
// let s : String = read_from_file("inputs/03.txt");
|
||||
// let (p1, p2, d) = diagnostics::benchmark(s, day_03::answer);
|
||||
pub fn day_03() -> DailyOutput {
|
||||
let s : String = read_from_file("inputs/03.txt");
|
||||
let (p1, p2, d) = diagnostics::benchmark(s, day_03::answer);
|
||||
|
||||
// ( p1 as u128, p2 as u128, d )
|
||||
// }
|
||||
( p1 as u128, p2 as u128, d )
|
||||
}
|
||||
|
||||
// pub fn day_04() -> DailyOutput {
|
||||
// let s : String = read_from_file("inputs/04.txt");
|
||||
// let (p1, p2, d) = diagnostics::benchmark(s, day_04::answer);
|
||||
pub fn day_04() -> DailyOutput {
|
||||
let s : String = read_from_file("inputs/04.txt");
|
||||
let (p1, p2, d) = diagnostics::benchmark(s, day_04::answer);
|
||||
|
||||
// ( p1 as u128, p2 as u128, d )
|
||||
// }
|
||||
( p1 as u128, p2 as u128, d )
|
||||
}
|
||||
|
||||
// pub fn day_05() -> DailyOutput {
|
||||
// let s : String = read_from_file("inputs/05.txt");
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ fn main() {
|
|||
|
||||
match day {
|
||||
Some(1) => run_day(aoc2025::day_01),
|
||||
// Some(2) => run_day(aoc2025::day_02),
|
||||
// Some(3) => run_day(aoc2025::day_03),
|
||||
// Some(4) => run_day(aoc2025::day_04),
|
||||
Some(2) => run_day(aoc2025::day_02),
|
||||
Some(3) => run_day(aoc2025::day_03),
|
||||
Some(4) => run_day(aoc2025::day_04),
|
||||
// Some(5) => run_day(aoc2025::day_05),
|
||||
// Some(6) => run_day(aoc2025::day_06),
|
||||
// Some(7) => run_day(aoc2025::day_07),
|
||||
|
|
@ -30,8 +30,8 @@ fn run_all_days() {
|
|||
|
||||
aoc.insert(1, aoc2025::day_01());
|
||||
aoc.insert(2, aoc2025::day_02());
|
||||
// aoc.insert(3, aoc2025::day_03());
|
||||
// aoc.insert(4, aoc2025::day_04());
|
||||
aoc.insert(3, aoc2025::day_03());
|
||||
aoc.insert(4, aoc2025::day_04());
|
||||
// aoc.insert(5, aoc2025::day_05());
|
||||
// aoc.insert(6, aoc2025::day_06());
|
||||
// aoc.insert(7, aoc2025::day_07());
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ use std::fs;
|
|||
|
||||
pub mod diagnostics;
|
||||
|
||||
pub fn char_to_u8(c : char) -> Option<u8> {
|
||||
c.to_digit(10).and_then(|n| u8::try_from(n).ok())
|
||||
}
|
||||
|
||||
// pub fn char_to_u64(s : char) -> Option<u64> {
|
||||
// s.to_string().parse::<u64>().ok()
|
||||
// }
|
||||
|
|
@ -39,3 +43,7 @@ pub fn str_to_i16(s : &str) -> Option<i16> {
|
|||
pub fn str_to_u64(s : &str) -> Option<u64> {
|
||||
s.trim().to_string().parse::<u64>().ok()
|
||||
}
|
||||
|
||||
pub fn str_to_u128(s : &str) -> Option<u128> {
|
||||
s.trim().to_string().parse::<u128>().ok()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue