Xah Talk Show 2025-12-18 Ep727 Wolfram Language, Advent of Code 2025, Day 3, take 2

xah talk show ep727 163fb
xah talk show ep727 163fb

Video Summary (Generated by AI, Edited by Human.)

Solving Advent of Code 2025, Day 3 (0:04), I'm working in Wolfram Language to extract two digits from a given number that form the largest possible number (1:53-2:10).

(* algo steps.
First, pick the largest digit in the number, but not the Last digit.
then, pick the largest digit, from the digit pool that is to the right of the digit you picked.
 *)

IntegerDigits[78129]
(* {7, 8, 1, 2, 9} *)

Drop[{7, 8, 1, 2, 9},-1]
(* {7, 8, 1, 2} *)

Max[{7, 8, 1, 2}]
(* 8 *)

Position[{7, 8, 1, 2}, Max[{7, 8, 1, 2}], {1}, 1]
(* {{2}} *)

Drop[{7, 8, 1, 2, 9}, 2]
(* {1, 2, 9} *)

Max[{1, 2, 9}]
(* 9 *)

FromDigits[{8,9}]
(* 89 *)
xinput= {987654321111111, 811111111111119, 234234234234278, 818181911112111};

extractMax2Digits = Function[x,
Block[{ xdigitList, xdigit1, xdigit1Pos , xdigit2},
 xdigitList = IntegerDigits[x];
 xdigit1 = Max @ Drop[xdigitList,-1];
 xdigit1Pos = Position[ xdigitList, xdigit1, {1}, 1];
 xdigit2 = Max @ Drop[xdigitList, Flatten[{1, xdigit1Pos }] ];
 FromDigits[{xdigit1, xdigit2}]
]];

Total @ Map[ extractMax2Digits, xinput]
(* 357 *)
Position[ {5,2,1,0,0,5,7}, 5]
(* {{1}, {6}} *)

Position[ {5,2,1,0,0,5,7}, 5, {1}, 1]
(* {{1}} *)
xinput= {6739459674389333459433695375559949344734767926833587823236783998689734978783695374574455875833736627,
2373132532343213331342343333323324363713834443362242454554343333223332333335533234623223382233732244,
2222441333231342122121622224212212232122222112222122311332222212273223433234222423211112132353251223,
2272421512212232712632222221523524213442212223262216623152226212222221225272522223212222532222422323,
2217222212362341131525335321122324234324223212742131242212142527224532246323122744833459212221122131,
6813346133475314448426121761834648738623643213726761185353582458174121486641462776426112246165435119,
2235322222212422321231252252212322241213233213221351223222222622222545214222213222322232422213132241,
7648868634667457694727389566453477683138824974478548353762562379434349956786463565646545578448865493,
2232322222272322552342542212222432512231313132533323713323222121122925282112215142213222222221221422,
7378621536927447566642237444326735875635564782944732267883374679374572291556321372283535258364561428,
1334223114253224534122334243242124273114222224322272334943143264254333322328312323224743333223222413,
5283934323221234344351874335434342554432424342322757233443633433247254423333534425541235222323429255,
6122264424275543533425551322224123443423422244434233542422226242126336524322442444524234552411263232,
3443433244333314444224322523243224242332342332231522315233263422237434428222432123142363223243122323,
2233352333342262213333232263345434333233236442643232343223622333542433543232553723343472444343144344,
1235322122234425513353323233233121313223332222322324126232232333222223222237222333233323333214223323,
4325536553242521223435445232395213355134524142322535362352345232535235334532452224141422535244355336,
1531221153311234144121313322135341553411453555332543414153122541252131523331312331122441352413256789,
2232231112132223322312321422222224211322231122222222222312222325233322325622212332222132322222222221,
2271154221775226562431222343772273735324566146362762534541555626247166372734737154373435715644351589,
1322321221282223222123242423224522232222222321132212222321512722312232222244311522253532222122221222,
5675373654492446328553454633465763638638344343656363366623636255464662661735553323346336465333638336,
6222154822345362222322222522826252516222212162122242142222622122427422231223222223423614522215652242,
6222632224242211424242122221223142223522122272314221322111422725222212233232111222111221311222122223,
7733645442442732531223245525486362495334532522464225353224187425436324512624552272122562562232464133,
3122212312222222223262221222241212424214221222222252222212222331144322372726213221422222122222222221,
3317564633543532241232338653138233333333364324334323332543322237249336434693237335433133563657333654,
2222112144232342525175554221722162744427124325232272237315162252521294737141422751612264275623365412,
5233336323444433338634333933257235232354342523921453333345233233432644331633334383243645338643368232,
6555744775753685565359587685688568577765366857785355475445486372239447764684674376558464546868574784,
3131322312625422313233136243434323233235451234422242642422221233433241342243343332222333122346552351,
5545548564544551455444547425574454555985534445454524586545294455554235363458655233939254543595655353,
2359665436622224221613324821315324832636221353316524645512225232332321223262434122723638222264123246,
1333332423122433422244223222413244221332222222331334124322323329146144322323222422225353223432143332,
2252325526527774625423122221535454723322284746512441336421532621335835341737442224474213326432923142,
5766753863736644458639676412563282136344433663331635335665536244554854252673336867536454745553535586,
5139931557883857995839397424342233394134332434843834938397764484863413686484933823989527723385843673,
7286354682444934529442314333841634632432443946348225224943437945312764582252426642212443354433463245,
5333223424222352523443254452734543444234454442121354623444212324542542244445314223324234433224341241,
2336332233323335432319231323313522133234131534443333333332433123523233523223166334633533319254346322,
3333333143332223113333442323223342232243235425354354334356334432335435533321344432432242742523542442,
2261454235142314252241242213243143364232222332141662222322248442436223423324264231211282313214412424,
3488334264566233754443373333343622327563345364254589363855559833246336332334356352363232364353368336,
1232122227141322242221232223224122312242228221224222246224222232213222212222221222222232212222422231,
3236763295122212613233243222122225436251538243322312245321313565232523264723325426332723223263241226,
1222222232335142362222123254322223622322422223426444223622322223434432433222525212484422336222122133,
2322424323244432341252312213322335622323221422345313125352332433421222212431335222342332124312432442,
3232821222332422722233212211212324153232331422222222321222323322223622272523212713232321332413272622,
3422652314245672235233363232413624422433323321424244162284333425222232322256212251232238721357223148,
7774837647487566658756757755755847647655586686578356759987875456786575764558968987878778565587969586,
1234223452224271232352455273726233633352227221354347283132212635572422643245234445451363372373482533,
5545555754466555455554847555655474545653574744655454656557557545555565555443556555756654565567525555,
5553554575554637555471355555154554444754485554555554465523825542545538455434435424455955526476554764,
3254522513355333222211324322242533123234124252622229333233422522362352423245261252142252422114324223,
2425344423234243432242213333252242333444451414325232234342213224352224134253221152324523223532441142,
2582466442443388322624223813222631742479616132436235434553312364912322732234884746223356613144486223,
3636223323332312624333322113312432342431432142262253223314236396612381142232422222213122423643323362,
7325293432331383666195334723512337573622433434353563239235379451235352335833733463443262233842631543,
2232624222332421511175521154321232335222932322461112227222122223213224257225223228222231413222222322,
4552958886759955368935997537673735734558749419267255538878465394745752594544365557345558264585655169,
2226216222224424524222422122422222224543262772122116426553224212223554631621145422424122825225242116,
1222335126326444352764222342426663636441411345223343625343235185633672347245263355582632531664629135,
6446446722356324442432213242214223324334335245335452632255422221143347414572397313223584225324331422,
5224345323222424434244363345434133334432432442422434334343444345442434433343442433454144443324346244,
5336333663337324323323235333336533343334125433374634569233686933546363236465133343459236212383233315,
3431212332243413441121331234133441131314434431411433224142211222213143223434341442213344211133456789,
5443222683292272324125357143312453332369372333522333233932316972333341214932333824122147432321723342,
2367262824212222291672572242672121223153327226222625761267322242612343213625422253225276322142114524,
6974563985343496663494433344643427344996686328654636476843646347684276485993646913458343453532176484,
2312521543522312123137242323132222221231426242224327114213221222242224322222552327224254122142112333,
6223242624251223217243624212512223241767442131244861652377673335441221242314494224319222352132462144,
2333332335532332253234215732233323322235422433832233633332422321433233353223223324633524336332332224,
2222222254612122222211642121222141234242212212122224252225222222211221224421423222122222532122221124,
7421232222222133463122231324223212213131262222222222262223222217223332222242112324223212223323223222,
3772242534373521568445363327624535346923343253955164573325436332351227545337435465955345446335669443,
5858895152574569257889189996518531539296968776753453347738719235827481499877364362498567754855232996,
4342235342363223564433432224563177215352333463431323332332366346334374333222313642241822536513753653,
3354323732241336324523344333384638354233345323235333356414435734334356233343815243323232355328535543,
3232231323322233322232342342232424122122233213223233212332333242223333133232223335322432333233233222,
4222124152125212126225265152124132222832522242612921242522725231324422291234253262251252922212222622,
6212552142225252118422223212232132222212722222213122224272253114265212154222226212272212113222621332,
4552534756756595545354443365654557336354364737575555533553643535547465544767455573755756641664753655,
2511242562394123244232225311322431521234233122422224223242358321213352344333234233713224232844173274,
5526573675275646255558956655553398735354554524555427427584565653555545563555555663555386643559595476,
4232222322223212512221132222227252235212222222124221221112232212223222453212215322552222422212122213,
3323424433432431244433341433443334252333344333423447143363335444343444424424333333334314334534734333,
9963543266528685935319932224777827787327354466945986687988877635834976575546746666448364958368484663,
6263444224532863343259522662665342226323162222857382232425236267222252462342222824722545227136623635,
3613233413353333333733232333232232314323633243331463333723643352333333533333264723363332314333323323,
3122425225223233212711545223521542342751432242342216624212233222124622255451462253213221324322312523,
4644734133536424434624843436434362694444315342324843447433442362627451364355523726343468233665395334,
4423752435257822384423397544537263283356855845353384355467172425447276333227266721254779455411724215,
1232222542232223232321322222187293523223312725724724421177222422132522224332622417141822722342212252,
1353462356374364544444752374433432367667363527433336443445574733653443133657644213156634465463366664,
3192682326222225434218233965252711232242242236626283422252542162524165353222421222322292921262515229,
3312233223612332333341332232322333242232223222131312332231232232133322132322233232332333263222412332,
3234443454533643613563332542531736363323533332113364323434522333534323225213524556624642433653522553,
2356547419343244352723362645244353646442345436343242314441245442452344326474324314552253321131474344,
4445493462456534126735454332732865436442644324962445644548387755234434462466476473934635423425734474,
3442442214253562342232334243274474423334242283443262663132232234435423322826434324322328667162354334,
9222423542321221122258446212213211172721233221222221223272256232642372212224522123332524124143432326,
4838673447445676256588638865556356667346668652334584256363964445648566415477386645366466656544567654,
4133131233343233241633333254242345323313343244335321522133232321433234243434543352332263632372375333,
5828945793549483935858838333432326954645791684532333453883537868337762597642674263434432357934531374,
2462313322354323424333646243334253243223325422243531637423233322332433424542344312432533643324436543,
2539348544557567255225664845627542364542463624645864444225522842247237721342534922336455362226526365,
4313432313333334433332333333722734342333313336332233233233243313333312233323332333333323333334133727,
1323322332333334352335343422333333313434243233132333332323433343143341333533143323443344234261233433,
4223243421322262122224452325212324411352242723212223222526252232122721211223222332222242215215722252,
2122243223224224122252224224652241224312121112242122848123262222222225222222222323223222224122241222,
5459575645652678467695654954544755554654556689544674556527565856685345655767347655553755585395765556,
4383447444642633635122355334333542442544584433334813341335344332326442333353544332353435434413446234,
2423344333433353334546425355243722444635353463435554444333335333343344352563531337322284832853331384,
4344441443463433342533145457735744443464345463435763434644743746347434463565745744767446646744313864,
3112622325223212232232184172222122311261131225132125212532233125325352242225221233322322254266254222,
2421274222332221222313121222321224121244232212223133243213421422123241222122144324214122214425232244,
2252234212322333222333523311221223223332432243433311222222311337442363222222245236321222321312511423,
2312212222222121212222322222224222222222122222222222221232222241122232322132132222222212232222222122,
7262448448421222424318593452122252371672822885228388224822722243224431442228622226178225632277243862,
2344523224412264412234421843923324224234342321232125413533424482134222423222714233232222322321642882,
1232232212212212121221223233422312211227122221242222222221421521222132222141223222212212313123412222,
2421555222443346242342325142532329744622464222455253942465222437421925254433254513524523242264522232,
4232364222233223225422625448524281542252232522532734642617212447412431262622232224732414524822558622,
2232222122231222222222222121123231223222222223221222222222212222312332222122132222222222231222231222,
1693242656125335113327232727222355534235553925255524352364142322551624375266322233222122623649145923,
3191622272845397635962226263372437781255371428539472315456786262324541857136172382276663246422552254,
2341631463341235353222762222332132322233235534224433242533322672626235543433335824222112122563848222,
4243352323393323322412422723421344531443344454133533423332252222525243363335353323442534322434624333,
4122122434441322212222232241231253242212423143524122122221222217222331222922224213122242232122112222,
8526423444659538534644434443534767654446388646433363374624465623394854334333835689839623378845467864,
4313524326322723333653229556672243256457353312433262243536222232243437572346242312182416365263363632,
3421432222332125453333232334338344233523333163632322363363515263335412227122266337233332633252733322,
2275513536253364556536326359452448225266635634263644244436526674634662244266625636275259662225628464,
2222136221237222222112825432222212642741375221233222222212222732324412221253641211214253222228243222,
2322321212231213122111233212228222323142251222221222232222462332222222122521122351322522224222232422,
7828633443736627726586266432543635144134379442252564462478743746263525583722448333372335374497538124,
3222251227311241235422312222323222264311412232322233341221223122222162422212226323422221231211513222,
5421435122248223255222326522521252121341244234153622222227423222224612542233443421224122174226163622,
4222222222222122113235623133222212322222112232222122252221322321212222222242222332223222321224223122,
4233252445312226722225223542226243322454643222228529422542432642233324322422222232232322222413121553,
3615624141464526353322824153676424526435724645414624562233359465646754544546524532454445363348642541,
3474387467558466355565563784234546623884345559524345534553425662362764666345824956865955463556564644,
1222522123722125232431423122312221313222222242227211222212221246224221223122282113232212223221222722,
4454441334924563343346322321343234496483913614877527343344493134728782224847974423844453215347431443,
4224223212291233225225132212253425261931487567442622576642326112223572438512272224122415569742162525,
6445335414254335336633343555235745445554554455535334535356454374324555334533853355353325455547325554,
6626581624635444362364651825256666457665474336555556556644435447463645326235256526535444414733534454,
5422576923223945122374796322152228884422452328642342753427334326724922222154422242222232232224147344,
4223124232132333633123141122222412256142215212333232322372323321121221222222223232322233232323324532,
3438133563332253313223323733342334333547565235332563234333513353132433224223733323433153334339332432,
2232222222222322552222321413122332322583424323222112232222343122123221632232922421112352212242351221,
2144423335464534433412253343495544445443423457247313364443722832342431533337637732644324464447454464,
3322412224224232642223433412311245672241314223325221311433242222221421474234544323222122432332342424,
3222332324232417422293428432253523184223543221221334231354221534223154231326547412423222932222232423,
6454435364652351435243121321513136424162525615464322641241355622412655562155263545644145116561433789,
5651549646656564446654548545658544637344446644764426624444646566644356545536335644427954453454845455,
1131338231231236463826221222271244933251332426223213122235217233532262423233333232222523523362232232,
2534465354338456343753333332343257573256325453237553435457423535435555555343364434344555542935444537,
4322212242322122412222273222322242322213244222222612322222214325222212223621321232352231122232222424,
5554555422343543534535553555455554872545238244655255353555555535425355545625355635545436646435534944,
2423442532223524223122234133414442223441212221427223222232221222222126522422542211125452121224231354,
1225222172436272232152224472436378228238344252537321232143222162232422241622442237322439142322224332,
2134222222621363445321422363333314221122222223244313241224232522243214274432346243462431342212242424,
2121443212224135231222223113432432222232318221222214222213222221232362211212122222447213222412414122,
1566355333393336334172656442374316389732383778336895623949463733633559423424688358375253739713963278,
2341254222222332212427223222222642221332224111722741226322434121222243214226221723244132622112112222,
6644642354573624554464472324223453542555645455422354444343626843445234444444464232522646245432242461,
3247436536134438548873464346333532755684353334675455432343435333344342364244863454955333432551323333,
1235215233244313532333113423336323344236333333463553332363232223353134733242353532332532433235323331,
9222226122322232272232261242721521223265414242325421722226222125122232222231213222672252242812254326,
1321222223122222222232223523415321322322222244221222222232233212323122123122223221232542424214322539,
3444232433344233344454133423435235333414322363245333434435335434413545373344433431434333433325353439,
2212231212222123222222225221229521332221225212351322113133232211222223562322313223231212312212132342,
3446665745854144677546554847575954733732467444426485447556754446464596854754334252247464584775744424,
4346262565225353555549454323452344542464454435533544545555222345534465553645355534534534542354335354,
1335222241344263233453344231323221127323221184223234423232221222322332323423213224332341222223121326,
5344331336363574334353641632133233443333323413442443343323633245842438635472374733453364333646334433,
9444334434444244644444345323745554354344344442435442435432433266524353434344383446433135455453554445,
4533434334344535345534333423444431344333442423245543134433552254344459432435544425422436135444413644,
2221322532223525175451345547567432822312232752333534963253638162474322348231743243225235335422414474,
5254537535635118228352459323444144421232545422514324214363242754457442221353275325294663252333452344,
2413222233253222363233382222333233152212233222212337331353332323322443221324233422332213312322322133,
2222353561222523135513522223232521222522222242432335222215412222223212333534452236531127122125221212,
2442384334158465433823365235674363435555433458234364573525766645443242362442362654345585533525374685,
3333362346234532333524724934541315323533324353333233612233443433323533333394347536227433666337336345,
3322344485213336532312332343343333354224833344334424424445333432633913344243324113436484424263233322,
3342333423262333433223332234432223332323323233423328434732342233331733323332432433321152213332433334,
3333313232317322332533333233335133721333233433822273382244353338333441233242825341253133329383633221,
2322243422312132242231323224322324422135322335433593322322522123323251242522132231334321332322335223,
5635623236946239558355233633854435593532134143353443243324233533164555442233345444454463345533536943,
3544244193244226529332426724342221335632234551423312214452252222623354242453451522223552173531454254,
8316113362363225333531324323422213323312453324252323432416222221353339564652322435137224342323323333,
7342633555612222253253223233314222132543262332234425246244543534553653523375332342323242224241345132,
2426443634943333523434526234444346524431545314136223423324424436344554416413323244144424537235436263,
2422345222227262832125222262122535563213221362163123126225342722332424326626434424452442652213242233,
2695512227221334661242722252244682332252321214131628211624213412225241322622222125224122222215272282,
8352222447535225362515335225152142332257652128665342313311225323322435782254832283123285572331272623,
2522423322322452621212352246423223132352222625543322132323122213622223136386123225124222253232522212,
6233333553433344335534335441536333444432144432234444434333424533233441434443342335444542211343343443,
4353732444512234333345235313431332543323433323223443373336442333335434932835543135333462635233343534
};

extractMax2Digits = Function[x,
Block[{ xdigitList, xdigit1, xdigit1Pos , xdigit2},
 xdigitList = IntegerDigits[x];
 xdigit1 = Max @ Drop[xdigitList,-1];
 xdigit1Pos = Position[ xdigitList, xdigit1, {1}, 1];
 xdigit2 = Max @ Drop[xdigitList, Flatten[{1, xdigit1Pos }] ];
 FromDigits[{xdigit1, xdigit2}]
]];

Total @ Map[ extractMax2Digits, xinput]

(* 17766 *)
xinput= {987654321111111, 811111111111119, 234234234234278, 818181911112111};

extractMax2Digits =
Function[x,
Block[{ xdigitList, xdigit1, xdigit1Pos , xdigit2},
 xdigitList = IntegerDigits[x];
 xdigit1 = Max @ Drop[xdigitList,-1];
 xdigit1Pos = Position[ xdigitList, xdigit1, {1}, 1];
 xdigit2 = Max @ Drop[xdigitList, Flatten[{1, xdigit1Pos }] ];
 FromDigits[{xdigit1, xdigit2}]
]];

(* alternative code. pure functional programing supreme.
 without using any local variable or constants *)
extractMax2Digits =
Function[x,
 Function[xdigitList,
 FromDigits @ ( ({ #, Max @ Drop[xdigitList, Flatten @ {1, Position[ xdigitList, #, {1}, 1] } ] } &) @ (Max @ Drop[xdigitList,-1]) ) ] @ IntegerDigits @ x
];

Total @ Map[ extractMax2Digits, xinput]
(* 357 *)

Advent of Code 2025