It was the most popular year yet with over 210,000 people completing at least one puzzle. My coworkers were impressed with the conciseness and readability of WL several times (they were using Python and Rust). I completed all of the puzzles, but I used help on days 23 and 24. I made the leaderboard (rank 57) for part 1 of day 13.
◼
Day 9 - Use of MorphologicalComponents
◼
Day 13 - Use of Graphics
◼
Day 15 - Use of GraphDistance
◼
Day 19 - Use of FiniteGroupData
◼
Day 22 - Use of RegionIntersection
◼
Day 24 - Use of Solve
This chart estimates the difficulty of each day’s puzzle based on the time it took the first person to solve it.
Out[]=
Day 1
Day 1
In[]:=
Import["input.txt","List"]//Differences//Count[_?Positive]
Out[]=
1711
In[]:=
Import["input.txt","List"]//BlockMap[Total,#,3,1]&//Differences//Count[_?Positive]
Out[]=
1743
Day 2
Day 2
In[]:=
Times@@Fold[#+Switch[#2[[1]],"forward",{#2[[2]],0},"down",{0,#2[[2]]},"up",{0,-#2[[2]]}]&,{0,0},Import["input.txt","Table"]]
In[]:=
Times@@Fold[#+Switch[#2[[1]],"forward",{#2[[2]],#2[[2]]*#[[3]],0},"down",{0,0,#2[[2]]},"up",{0,0,-#2[[2]]}]&,{0,0,0},Import["input.txt","Table"]][[;;2]]
Day 3
Day 3
In[]:=
inp=ToExpression@Characters@Import["input.txt","Lines"];
In[]:=
gamDigits=inp//Transpose//Map@Commonest//Flatten;epsDigits=1-gamDigits;FromDigits[gamDigits,2]*FromDigits[epsDigits,2]
Out[]=
3148794
In[]:=
filter[list_,i_,isOxy_]:=With[{common=Last@Sort@Commonest@list[[All,i]]},Select[list,#[[i]]==If[isOxy,common,1-common]&]]
In[]:=
calc[l_,i_,isOxy_]:=If[Length@l>1,calc[filter[l,i,isOxy],i+1,isOxy],FromDigits[First@l,2]]
In[]:=
calc[inp,1,True]*calc[inp,1,False]
Out[]=
2795310
Day 4
Day 4
In[]:=
inp=StringSplit[Import["input.txt"],"\n\n"];numbers=First@inp//ImportString[#,"CSV"][[1]]&;boards=Rest@inp//Map[ImportString[#,"Table"]&];
In[]:=
timeToWin[board_]:=NestWhile[#+1&,1,n|->NoneTrue[Join[board,Transpose@board],rowOrCol|->ContainsAll[numbers[[;;n]],rowOrCol]]]
In[]:=
score[board_]:=numbers[[timeToWin@board]]*Total@Complement[Flatten@board,numbers[[;;timeToWin@board]]]
In[]:=
score@MinimalBy[boards,timeToWin][[1]]
Out[]=
14093
In[]:=
score@MaximalBy[boards,timeToWin][[1]]
Out[]=
17388
Day 5
Day 5
In[]:=
inp=StringSplit[Import["input.txt","Lines"]," -> "]//Map[ToExpression@StringSplit[#,","]&];
In[]:=
linePoints[p1_,p2_]:=NestWhileList[#+Sign[p2-p1]&,p1,#!=p2&]
In[]:=
countOverlaps[inp_]:=linePoints@@@inp//Catenate//Counts//Select[#>1&]//Length
In[]:=
countOverlaps@Select[inp,#[[1,1]]==#[[2,1]]||#[[1,2]]==#[[2,2]]&]
Out[]=
6397
In[]:=
countOverlaps@inp
Out[]=
22335
Day 6
Day 6
In[]:=
inp=Import["input.txt","CSV"][[1]]//Table[Count[#,i],{i,0,8}]&;
In[]:=
f[n_]:=(cur=inp;Do[cur=RotateLeft@cur;cur[[7]]+=cur[[9]],n];Total@cur)
In[]:=
f@80
Out[]=
386640
In[]:=
f@256
Out[]=
1733403626279
Day 7
Day 7
In[]:=
inp=Import["input.txt","CSV"][[1]];
In[]:=
calcAt[f_,p_]:=Total@f@Abs[Round@p@inp-inp]
In[]:=
calcAt[#&,Median]
Out[]=
355150
In[]:=
calcAt&,Mean
#+
2
#
2
Out[]=
98368520
Day 8
Day 8
In[]:=
inp=LetterNumber@StringExtract[Import["input.txt"],"\n"->All," | "->All," "->All];
In[]:=
inp[[All,2]]//Catenate//Map@Length//Count[2|4|3|7]
Out[]=
239
In[]:=
digits={{1,2,3,5,6,7},{3,6},{1,3,4,5,7},{1,3,4,6,7},{2,3,4,6},{1,2,4,6,7},{1,2,4,5,6,7},{1,3,6},{1,2,3,4,5,6,7},{1,2,3,4,6,7}};
In[]:=
solveRow[in_,out_]:=(correctOrder=SelectFirst[Permutations@Range@7,order|->Sort@digits==Sort@Map[inDigit|->Sort@order[[inDigit]],in]];FromDigits[out//Map[FirstPosition[digits,Sort@correctOrder[[#]]][[1]]-1&]])
In[]:=
Total[solveRow@@@inp]
Out[]=
946346
Day 9
Day 9
In[]:=
inp=ToExpression@Characters@Import["input.txt","Lines"]//ArrayPad[#,1,9]&;
In[]:=
inp//BlockMap[If[AllTrue[{#[[1,2]],#[[2,1]],#[[2,3]],#[[3,2]]},p|->p>#[[2,2]]],1+#[[2,2]],0]&,#,{3,3},{1,1}]&//Flatten//Total
Out[]=
554
MorphologicalComponents[9-inp,CornerNeighborsFalse]//Flatten//DeleteCases@0//Counts//TakeLargest@3//Apply@Times
Out[]=
1017792
Day 10
Day 10
In[]:=
inp=Characters@Import["input.txt","Lines"];
In[]:=
pairs=<|"("->")","["->"]","{"->"}","<"->">"|>;
Day 11
Day 11
Day 12
Day 12
Day 13
Day 13
Day 14
Day 14
Day 15
Day 15
Day 16
Day 16
Day 17
Day 17
Day 18
Day 18
Day 19
Day 19
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Advent of Code 2021 solutions in Wolfram language
by Michael Hale
Wolfram Community, STAFF PICKS, December 27, 2021
https://community.wolfram.com/groups/-/m/t/2432017
by Michael Hale
Wolfram Community, STAFF PICKS, December 27, 2021
https://community.wolfram.com/groups/-/m/t/2432017