Xah Talk Show 2025-12-26 Ep733 Wolfram Language, Advent of Code 2025, Day 5

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

In this video, Xah Lee tackles Day 5 of the Advent of Code 2025 challenge using the Wolfram Language (0:06). The problem involves an inventory management system where elves need to determine which "available ingredient IDs" are "fresh" (2:16).

Here's a breakdown of the video:

Problem Description (1:48): The core task is to process a database containing a list of fresh ingredient ID ranges (e.g., 3 to 5, 10 to 14) and a separate list of available ingredient IDs. An ingredient is considered "fresh" if its ID falls within any of the defined fresh ranges (5:56). The goal is to count how many of the available ingredient IDs are fresh (7:32).

Concepts and Definitions (3:42): Xah clarifies three main concepts:

Ingredient ID: A unique identifier for an ingredient.

Available: Refers to the list of ingredient IDs the elves currently have.

Fresh: Determined by whether an ingredient ID falls within any of the inclusive fresh ID ranges (5:42).

Keyboard and System Digressions (4:18, 30:30): The video includes brief digressions where Xah answers a question about his Ultimate Hacking Keyboard 80 vs. Glove 80, noting his comfort with both, and discusses his recent Windows 11 upgrade experience.

Solution Approach in Wolfram Language (32:59): Xah demonstrates how to solve the problem using the Wolfram Language.

He first explains the parsing of the input data from a text file into a list of ranges and a list of IDs (20:18).

The core of his solution relies on the Select function (42:58). This function is used to efficiently check if an ID falls within any of the fresh ranges without needing explicit loops or recursion. If an ID is within a range, Select returns that range; otherwise, it returns an empty list.

He then maps this logic to each available ID: if Select returns a range, it's counted as 1 (fresh); if it returns an empty list, it's 0 (spoiled) (52:51).

Finally, the total count of fresh ingredients is obtained by summing these 1s and 0s (54:44).

Result (59:18): Using his personal input data, the solution correctly identifies 611 fresh available ingredients, which is confirmed as the right answer for the Advent of Code problem.

Conclusion and Support (1:02:07): Xah concludes by summarizing the elegant Wolfram Language solution and invites viewers to support his work through Patreon, Amazon gift cards, or PayPal.

given a list of ranges. e.g.

3-5
10-14
16-20
12-18

and given a list of numbers e.g.
1
5
8
11
17
32

find how many of them are in the given ranges.
xah talk show ep733 rSSZp
xah talk show ep733 rSSZp
Select[ {3,4,5,6}, EvenQ ]
(* {4, 6} *)

Select[ {3,4,5,6}, EvenQ , 1 ]
(* {4} *)

Select[ {3,7,5,11}, EvenQ ]
(* {} *)

Select[
{{3, 5}, {10, 14}, {16, 20}, {12, 18}}
 ,
Function[x, And[ 17 >= x[[1]], 17 <= x[[2]] ] ],
1
]
(* {{16, 20}} *)
xinput = "3-5
10-14
16-20
12-18

1
5
8
11
17
32";

With[{xTextBlocks=StringSplit[xinput , "\n\n"]},
With[{xrangeList = ToExpression @ StringSplit[ StringSplit[ xTextBlocks[[1]], "\n"] , "-"],
xidList = ToExpression @ StringSplit[ xTextBlocks[[2]], "\n"]
},
(* {xrangeList, xidList} *)
(* {{{3, 5}, {10, 14}, {16, 20}, {12, 18}}, {1, 5, 8, 11, 17, 32}} *)
Total @
Map[
Function[xID,
With[{
xSelectResult = Select[ xrangeList , Function[xrange, And[ xID >= xrange[[1]], xID <= xrange[[2]] ] ], 1 ]},
If[ xSelectResult === {} , 0, 1]
] ] ,
 xidList]
]
]
(* 3 *)
xinput = "474206951121632-478696506672479
163116829426271-165160349859997
221483132425635-227257813060759
286651418242134-286842665051583
265273471140475-265273471140475
451276424597513-451433579120801
460273660026930-460273660026930
94797035470525-96066978979415
23791479231530-29481674603674
177056653568318-180135598430454
8074420174647-8074420174647
159870996546192-160223340371509
493535738102510-501433703837630
36291396245273-36781601196010
454641213097579-460273660026929
95563306986468-97195331245037
451276424597513-451657340081208
546082097949047-551569549050804
37889708704621-38632926811795
156116673176538-156795854376032
318890700006518-320985394024093
448268191773761-448736609110916
447979946241814-448426415177388
514638305196412-521083042789600
395225066061785-398627329385954
105258696335727-107679867728032
385992033414658-388870188182791
414361022789066-419987054903495
285045100572117-285937012259183
430487856840098-431890116435920
35122963889957-35869804621715
284269895970975-284614259778823
326124465621449-327749467362448
446026463821565-446220094461623
465284763947290-467816103374356
32983534459426-33493657390743
113467760113647-113467760113647
181884032546028-184935575624873
446504566009603-447277720564033
213053649174492-220137894670312
282370844250193-283152921829315
355184444240747-361110954613539
84255547073648-86393099794509
546082097949046-546082097949046
242147851735696-246960153847500
224131569075399-229915436140085
144901399368227-148891314579418
41777491356284-47286614926294
152445628560287-153239201829814
91658406315313-93278376835615
526658787092150-530109060211808
495407364825092-498175662941144
191880524960857-197718954915537
280700290602006-280700290602006
433678529207652-441496379781812
155249005741170-155865703282978
398627329385954-398627329385954
18075550402375-18075550402375
429706142427715-430943462711950
533939497845125-539097312323333
426095935026674-427289205070865
517332148961796-521083042789600
304096046559104-308673206518148
35122963889957-35869804621715
467816103374358-470837045125033
32846971641746-33317652844719
36291396245273-37081188759157
62008049313581-67360705645304
447277720564033-447436835523650
448268191773761-449014424738699
157791848150876-158373937072023
484384210243381-487327226446198
102398174918654-109560136682500
333844758556601-338841582089530
56272003912757-58357361231313
153239201829814-153921234619904
156795854376032-157018736453102
362952781546303-368162797560091
427092480181021-428556803797008
161225750540101-163740666065303
201840159045384-210247743624639
333844758556601-335824212471439
256426486380915-259710425900307
73857950453528-79834487304378
156795854376032-157441514357298
204560279231634-207169772395680
96689935732370-98123108728555
181884032546028-188092492942674
233242396110760-236945140059312
36076944990662-36641186279202
97919009847911-99360997626746
433678529207652-441496379781812
62008049313581-66114165909197
419987054903496-419987054903496
51102230199747-56272003912756
34025641735119-34840962485546
98781985034168-100238722908994
423518976606316-424674210550482
422451935448724-423713524026933
156536537831977-157018736453102
503549310876129-503549310876129
523733106249917-526658787092149
265273471140476-267973960106675
30886634876589-31591112075079
292612861644088-292612861644088
70891543129194-75848549883975
246960153847502-248718868495461
31233338925338-31700383599417
292612861644088-299350882886655
33493657390743-34025641735119
158373937072023-158752269207598
476141323793288-481476349014138
374765938920650-374765938920650
164791107569353-166862587798244
121790193987724-127603307921507
539097312323333-539097312323333
406433433009252-407968528710061
20909841849718-23791479231528
158157894857538-158752269207598
220137894670312-220137894670312
158373937072023-158752269207598
154853636902534-155355261913000
233242396110760-233242396110760
427874208344273-429218239198983
30938823286025-31700383599417
287032654982658-287710161185388
484384210243381-491425570692368
113467760113647-118202241525921
352568021349817-357510855858018
446220094461623-446667187311787
315351080319782-317769513294034
447000146266159-447277720564033
285664396292982-285937012259183
313992258363256-316199214336478
425120248392354-426578156940014
316824623560003-319348914490324
121790193987723-121790193987723
11435042565907-18075550402375
326124465621449-327749467362448
283416050257002-283594458610033
450189585363090-451072142040970
424269664355911-425786587347369
191880524960857-197718954915537
159213274321170-159550331839221
428882516928698-430179085485632
157018736453102-157138467854621
41777491356284-47286614926294
133310827834292-138802393853740
374765938920651-380521555125425
173744137527309-177056653568317
253267573362775-259710425900307
93915625214052-95273670497821
167738204847852-170477024849447
281828050086487-282570850383408
442888318917699-443525419690011
151088946983425-151770259956020
368162797560093-370647793816234
305981892385120-308673206518148
344794295431435-346305021230738
346305021230739-349892477733302
32846971641746-33493657390743
554466864370744-559452028950606
135515426750417-138802393853740
273203497570080-280700290602005
90563219614481-92274317917310
31591112075079-32064305301227
383509644012270-391774042870386
311985870835778-314378332099132
284614259778823-285349617755276
286147633139899-286472554717591
503549310876129-510921398263023
1730804549696-8074420174646
166516486496576-168838972520814
92714816788170-94137721164754

223088071752434
270021781550374
19861251863551
495081682189435
371250661278738
351911374597874
317341980517944
518095824375612
224536918689073
221029732367453
61403504405681
273355827067366
370391472835728
157065210331352
551768444645263
246078791260883
179130084251318
500203213218445
99301952849061
452147271981544
29033828904374
287625816716391
143870236683875
119284558613859
50874786763493
182689107024889
516979814973903
89547422768499
76946946825534
181315865894048
359088851519563
218159149062555
409279613182253
223534125982922
358461639733713
539068818352496
6458234043974
259029296384958
52749242490910
162691489777102
259055182481392
139999335631219
120263073798351
29984295193748
73685079619156
50413385873948
36416668973923
175717393342582
484443471099938
292512459195072
238454370877050
561893878360702
540789184100507
116598469815479
166066168812007
193832578260465
141094541466473
112060209157780
241046875892796
337976902869622
258806818731760
230943564739198
362719537908922
1282950124751
392221597581054
330245530859647
144605465226635
453754540219669
166940202152182
114508675242016
215684162306255
463086224074911
265878780486189
200647521640298
156727205995835
13809907435391
51876642068386
393735583477840
270413314784579
116827496171143
415495911314019
43009195802504
501967800589156
376645977108820
329913197208087
419662081750340
497877924554468
436545216477995
30171029466183
319532294827672
206379572541104
264070764279094
540037480400257
62143544872580
297420571618115
271012194437533
201751714737593
322283761808484
103784237812965
64040787892716
560945815169559
368394218841577
105031140469366
360583232414923
54885476104339
331695416309357
282279370049869
214906394540207
424188536929083
81696578534560
449024629875446
236782853719747
185120454920349
359937820371017
505408044271805
160870658124271
165522163948109
80009607223344
266015292689045
254698678720478
283362864869895
422438869040661
513060823699172
158610577188717
327107957891634
514072919756202
536553026882318
129747419293306
521310735404884
262015900396830
222155269471781
37586115032327
426914545204500
495408247708606
156329494496832
300292085654255
288264389210812
239892456205938
25814270539133
402198507339885
507366673437603
135713254388144
136963516640935
520496426785968
310194635672440
487141351757539
303444137642016
170431333530861
325538207189728
347468818245321
400733162897305
547734140392367
101033438838983
225344216055317
236802373762722
92499045621776
511804609938715
381173785656322
139514175627598
98855095255611
472934505554282
256587499191501
18883837461448
527142438622640
130353625482725
166305791304107
89374824471055
20689879604576
324319347937453
473264568736535
378879374810791
172345231521390
352562747477536
534070940249852
318427842637627
170042178582712
299466484947606
532610689198917
5870315612211
247770628008258
86966155739755
523600118302497
23453886736072
555189616491025
170050287789263
328534969818967
109954863531314
135239008653272
158986444351967
37072655423059
560131192036686
285625744143040
22840828689992
132838499353622
218150101951975
455725091040256
386587750540200
36099527197058
307467560364871
206551943677949
449906104849788
356836487956532
291069827709805
128590111548774
114078013833364
444611659310432
409957709263819
515480072802457
285669192108509
179991535774828
111340172879338
540311007495116
510395354432362
402682115848418
35685845288183
192943900298336
72986816453385
441099867190412
436024571266296
435188912162268
325568731019378
199951628412139
325954082653254
398171394066834
153756164082017
466103157098406
93023111765523
390200519625791
240620744618939
194346981556533
557708411866679
380902238039611
88048612767857
283885502716009
257206213247030
258468623810497
378182233085500
448703585629648
450911617019991
152831616757855
91209707168903
278502227373025
307603026612064
111452522222340
334825466185692
239357787001844
231792962199532
380280922397766
393868689482879
164143216642777
60203676643895
365455708103716
521126323552078
127788789982839
378319701591257
468021095631327
507402622773592
138908846380526
146140794072561
13217681354698
73575842818261
260227885917623
162981117173848
543626914232592
335213449285921
84278681405978
358365524300765
337647861631728
360213414314376
413461293213266
438480263080164
266532694184569
551909029266790
18840200999480
426474125072415
291996070920127
368727440908000
521473560495109
135073535519333
162844278903792
114936875811292
280368547259702
339709159603448
466664070493461
85029770303183
331005032971140
213544481098049
532470657257132
197445729033351
528854275578141
298616823720203
107078606173957
390124670279809
452324522151301
362906604128975
295225606756
443424602898963
197501216422283
53176108014747
310384238138865
530393798010324
28983372100292
386664080151757
492574619956017
296056648422771
458461562391905
88803112175999
488290757844066
363523585149469
235255792068033
216810672099229
290540111611740
272543650763591
103351440466075
163056758446028
501998930352681
536784302787416
229610229385154
81981287797313
531240748221434
160299153162023
460066720770136
466620830744652
402368303224296
413110588251521
5068444135489
76125735574934
3274219798553
197073247261862
1194183641823
135193229920632
518649932747626
423562691309143
277908237488633
522788793218872
366372558124219
414370173634707
453133640426744
320001935082551
195570475865108
245869207839287
297721586652834
294217376518673
187708664191840
57065542148564
141277484265115
320190363178468
525519662496854
496547137423291
330152029231285
152841379949376
143690410203236
230190769342235
353825968231621
30121021302178
302311408229984
433248277608850
446616953033276
59097220253818
133451563176600
507071430261932
304640592825543
454847587135032
137292410045741
147031770612190
123040727378327
36967132911332
247039840283407
258371340915990
348336455994443
30037820341177
494984142370551
249579005646118
112852592221081
14439268298774
45659323237660
417379795503043
516299310702734
296987058133180
476023431534635
530493869803029
328337714733998
514122724318053
126038997122039
489701108561056
386292312048208
340737647836783
83009317440666
495456006026699
519549974939661
105294698236698
122310240596059
58596596064463
183916807386800
295419217880752
59784919051037
347817135713644
464130978923973
78482363429773
97421506157199
334187289278917
357336639481841
426174602981363
175520788180707
456771175730283
429872561762402
296413366050984
442156856311435
186185464640689
67367796528845
249720795117387
17883788595868
446962384256221
164096620402662
534949468239638
129946254087722
531734670468640
201341163633338
497613733892298
340245104149934
111511676534847
106178195603363
14321611490431
384880806115291
269626725689008
428845626549793
318691963088238
554520522587465
334974477288745
347457997461633
57413933230814
296978316879467
144945821712282
49019844383485
549045944783764
283790957595809
52285656921052
101210808698261
43935411878913
476141517494655
184991681548904
366709120667665
129508282508039
458964131007499
222969923443961
455593613614063
272505565942622
189316868409866
251436319956298
136018101457513
520734973671297
86536969549099
301912095264721
16548839509980
129822231532846
298090032915807
42717363628087
247524487587330
456683295853346
518604313246064
359188113876376
262359876044005
120154871424386
176060625874767
290536815704518
379727824609535
435189738624192
48826141747090
80001627750978
367530511335750
515694330636226
256017682942913
177746565276764
4637586676819
400979244742798
122181285390822
311682686260338
281672522538871
125145753647770
163837920527266
297961544568568
326129531009713
161707330550608
117798629184667
496791629820978
3749637523520
48297049709268
33111121799864
524199426770766
99997556728345
530709614611623
210723636301350
103849947333502
101182397465316
383836184389315
312008630079247
149098177752576
307919281495495
333571610014178
216709789156967
542226232516826
479687836521115
80900062641518
2794240759559
353244372652550
531288016427676
74140952311616
10238838895769
477033994158632
60346023985574
373630434334120
474827953431041
316192990703903
71072784706168
200991393828332
556920587086670
1832877874030
85581077158251
84360675689720
153440493550361
323823962035654
111286323750485
490065572374788
158736381698461
475957856991163
446039943235892
335600178188392
209202197587655
17195718351118
330007972306578
86502843653138
154900062863645
227304342071189
380716709221658
29815920090786
290838704434493
308940088877196
472266931818639
270685825985888
153696708329327
233616705062814
104466670300929
50538900664137
387367757297700
524677495916189
485539953288562
38331320221008
428900861834753
553638011219752
455548446707443
181613697015170
530264790867794
81028931474322
305996930763795
201477683890335
498307848238921
130570768099454
505486500187127
214995971033173
256822451338339
509273213400126
326617798052009
194503230756122
176286678698200
80670064320307
57949393701474
90240589382929
73319745027839
107080367900956
519267225675305
279990915801781
45798758351337
255356242697791
119336371402715
405004240680253
164319236907435
60679606039679
405137744770631
119788025872187
479346410610416
102868667239941
377480815579297
541859022195375
141223101413834
6441706450806
459101677299468
407640080505715
210782769329886
8251423146556
324817871769429
244398670257102
531758672912647
549846434609640
554621793191731
441198395412870
167690382532407
204358470954307
327297084005399
283674857626597
340112789238005
515572099024377
475849383277112
460845565517178
537717915346514
285042762826606
497378597557679
110133563039754
467276172216499
430829534383628
354528996808229
521337952913917
335322956312199
549062660404420
265097025550563
102075321237428
297833704406518
470859240654724
396637989072293
124766252927916
439127245280443
527388713285592
190800237352166
421712010557061
257448699832011
78123610081367
33295056914226
261057783051818
277201904648250
114903261994110
387585005228245
101710708751575
442353412203381
391467442675649
271001202720393
260954740961867
56349951849335
397460484954597
87138085439485
12080250316178
473730500534477
138023568515327
337489167333109
524243497868657
293004081456754
321507109011210
425684216297466
423732578745021
223803880407525
80909932674976
382617354133511
190509484605699
237676098512505
370649295643765
300206873157004
358470520810648
479027978148480
130039961639535
430187093518040
313747516330216
517031518472646
364782724735406
115655573904801
440889155929916
212512218129287
460924931240155
45660377321709
127109960940802
41430417051443
562727823587795
531965745760446
790026153257
359870313886225
511010751621163
274372242310522
35688116692737
281565836301512
476500705984799
408675106844089
496650495924604
83776056927987
441847390675306
34638423418971
392447738096520
426998592990645
430709508690479
442423057116872
212786145047657
56329106790814
556279064193451
40819911965586
13813461561409
384118262617262
71370858221375
505378118125519
142042920942679
555936569563920
122285701568296
205550841501088
492430782497684
474085714169449
170610887190824
102825279043222
323846490009555
368975092849902
393867636172894
295883269485150
444263212804639
523548920968243
2879223053858
79747870148934
513139821038696
140525847893692
133516855428032
17325541818361
246952619761831
484740093033058
555244115041290
311713904232570
117859391237619
361244948353640
198504848086855
540145106260324
271758716257519
64380604549889
381710264282402
359746994121256
524478881091354
378050786484211
199073271168708
259303536819025
560041101049243
152438516140400
305241955667189
422295205957801
514700302626628
427604019295848
108521111422061
292878864954570
432839044317146
140444020146060
381124660365092
550717999236323
535413853919100
54781997466765
244207474544238
145887580106669
344093275079108
435596043498079
159329118873978
14156439354461
254515410671168
19161395150428
128014286324923
551393589992997
177140787651043
267910122877562
257698619121475
60783832297863
481368293698229
516443438735959
166906507851797
388498165601853
346937423794451
363773152476224
446810949913238
287831704023263
260649664958223
36941712245339
411033212343476
67376607306751
312776325896133
411971896383847
322940921080867
76045231773926
295290150725602
512482628619412
278999585151797
238824960198994
290949374439373
276726410433653
33747819136603
487521691028456
109682911361509
123541770491702
545013549352927
288319955308522
240164221249667
369113450742946
28829754291308
309213636632198
53876632452273
333122885956313
401290161732988
132241656237578
183327091830305
383465856388241
130366141055276
115144380177532
191151390324875
215087894351145
470404698602934
320988015597768
177851286257449
410780188123261
56132232548225
120808642559072
557120110360649
179973761295818
322923858813301
97370067872662
243215651288841
82151966644633
242734746527839
416901000195590
406835939941991
139939598119945
212025468616751
422853006376395
111343612643682
501612457859222
271663711751269
485662133677821
82385110282996
137812871936184
340256087147983
151528800493804
32918505359592
335867422460595
431264376239730
337037317098212
439487534999581
516906869728841
549413748531863
484319682739385
11745035872345
424402992477524
316795293852213
57130571219706
33489095390719
102802101033973
477616892516772
69165864571745
423581028549768
494530943700072
226501395595833
368475175695322
486133579090243
403640425642754
218465073101264
332139078806808
206206087750420
58387903111567
219756597964999
163664130255811
85627327972043
23291457591750
237430952417504
223085562668514
57631464348833
342015246125796
491326681684136
241336670878479
140051127886207
514598956975220
154606149977284
337265013261252
320230064418857
45223257152942
159061927174723
336302380927060
200189519417638
54564162252631
424869052427160
223236246858630
489150335061712
420549879955055
218337380713169
539804898780061
142682760504643
492910827605105
325894548265172
409430360115113
328276879326485
318153082950028
514154371932506
91744176104857
107116110962253
484825901367293
510440990054230
204555593175722
20515044552116
506329732228421
157233020751395
179016163799963
476846793195221
168564628169929
443344887294595
560581619238478
59422800752875
21869903453990
119657838631121
35545234118768
320780474914773
482136916674159
255587108103133
67648893426588
166650031232298
321026201109988
52352055283047
337198664445297
53797990153413
104515612302908
475015843580157
541218225341714
50670584916435
114883139262884
140002888676221
47061749126031
442710158275852
531746330738217
31963791047933
91409962926731
486896130004939
332653140968770
147228562462797
194926031429720
422417442308490
439328311044312
501671400230216
133926863946227
72065955365543
203211947687544
27047932658955
368748032884975
100486225335859
119080087777829
166393001965786
109028859192489
201040965637131
75209525971182
324103738646730
422074932635161
398603130027045
410554878735568
399261497921759
409592883489751
371902829433872
494936796227537
361075719659349
114228171918299
513900137323225
258450125546518
428965252783690
202599567656653
385519535934695
531259433554396
253333333577711
373235119169425
446798245198867
161340343519381
463607442164246
401489159535949
375728971367206
534153037736865
457412560644966
63608812693258
489762848777284
238330264463217
78234478725157
28821961631271
522105822381002
266317635564208
499853071271858
328153226526636
123034752704259
463640917963690
256064796669921
115829031734270
505091943383852
192487794660961
539971462389083
94766668458903
193527710949427
55115320790365
219460118822297
338614839830678
229679056409207
321847178693353
400788029204764
445782875057701
548251774127538
494149881361840
46224178842572
23975312042286
68027532011390
445814373870017
467228542245571
524112823431071
394796507025136
339024629171797";

With[{xTextBlocks=StringSplit[xinput , "\n\n"]},
With[{xrangeList = ToExpression @ StringSplit[ StringSplit[ xTextBlocks[[1]], "\n"] , "-"],
xidList = ToExpression @ StringSplit[ xTextBlocks[[2]], "\n"]
},
(* {xrangeList, xidList} *)
(* {{{3, 5}, {10, 14}, {16, 20}, {12, 18}}, {1, 5, 8, 11, 17, 32}} *)
Total @
Map[
Function[xID,
With[{
xSelectResult = Select[ xrangeList , Function[xrange, And[ xID >= xrange[[1]], xID <= xrange[[2]] ] ], 1 ]},
If[ xSelectResult === {} , 0, 1]
] ] ,
 xidList]
]
]
(* 611 *)

Advent of Code 2025