One of my daily routines is solving A-Puzzle-A-Day by DragonFjord over coffee in the morning. This unique and addictive puzzle is designed to provide a new challenge every day of the year. It consists of a calendar board and eight distinct pieces that you must place together to leave one specific month and day visible, corresponding to the date you’re solving for - like today’s date, a birthday, or a favorite holiday.
I can sometimes solve it before my coffee gets cold, but other times I struggle. So, I tried solving it with Wolfram Language.
Create board
Create board
Create a calendar board. It can create any date from January 1st to December 31st.
The top two lines represent the month and the five lines below represent the day.
In[]:=
(*initialboard*)initialboard=ReplacePart[ConstantArray[0,{7,7}],{{1,7},{2,7},{7,4},{7,5},{7,6},{7,7}}->1];initialboard//MatrixForm
Out[]//MatrixForm=
0 | 0 | 0 | 0 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 |
The above matrix represents a board in the following state, where no piece has yet been placed.
The board for 14 March is as follows.
In[]:=
(*adayboard*)dayboard[m_,d_]:=Block[{mpos,dpos},mpos=QuotientRemainder[m-1,6]+{1,1};dpos=QuotientRemainder[d-1,7]+{3,1};ReplacePart[initialboard,{mpos,dpos}->1]];dayboard[3,14]//MatrixForm
Out[]//MatrixForm=
0 | 0 | 1 | 0 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 |
Create pieces
Create pieces
Create eight distinct pieces. Assign a colour to each piece.
In[]:=
colors={Blue,Darker[Green,.5],Orange,Red,Magenta,Green,Cyan,Yellow}
Out[]=
{,,,,,,,}
Create eight distinct pieces. The pieces can be rotated 90, 180 or 270 degrees in orientation or turned inside out, giving up to eight different ways to place them.
In[]:=
createpieces[base_List]:=Block[{p7x7,p7x7rotates,p7x7reverses,p7x7s,compacts,pieces},p7x7=ReplacePart[ConstantArray[0,{7,7}],(base+Threaded@{1,1})->1];p7x7rotates=NestList[rotateMatrix90,p7x7,3];p7x7reverses=(Reverse/@#)&/@p7x7rotates;p7x7s=Join[p7x7rotates,p7x7reverses];compacts=compact/@p7x7s;pieces=getposition/@compacts;DeleteDuplicates@pieces];piecescnt=8;rotateMatrix90[matrix_List]:=Reverse/@Transpose[matrix];getposition[list_List]:=Position[list,1]-Threaded[{1,1}];compact[matrix_List]:=Block[{rows,cols,nonZeroPositions},nonZeroPositions=Position[matrix,_?(#!=0&)];rows=Union[nonZeroPositions[[All,1]]];cols=Union[nonZeroPositions[[All,2]]];matrix[[rows,cols]]];showpiece[p_List,col_]:=Block[{comp,plot},comp=compact@ReplacePart[ConstantArray[0,{7,7}],(#+Threaded@{1,1})->1]&/@p;plot=ArrayPlot[#,ColorRules->{1->col},Frame->False,PlotRangePaddingNone]&/@comp;Row[plot,Frame->All]];
For example, a rectangular-shaped piece can be placed in the following two patterns.
In[]:=
p1={{0,0},{0,1},{0,2},{1,0},{1,1},{1,2}};p1s=createpieces@%;showpiece[p1s,colors[[1]]]
Out[]=
On the other hand, a T-shaped piece can be placed in the following eight patterns.
In[]:=
p2={{0,0},{0,1},{0,2},{0,3},{1,1}};p2s=createpieces@%;showpiece[p2s,colors[[2]]]
Out[]=
The other six pieces are similarly placed as follows.
In[]:=
p3={{1,0},{1,1},{1,2},{1,3},{0,3}};p3s=createpieces@%;showpiece[p3s,colors[[3]]]
Out[]=
In[]:=
p4={{1,0},{1,1},{1,2},{0,2},{0,3}};p4s=createpieces@%;showpiece[p4s,colors[[4]]]
Out[]=
In[]:=
p5={{0,0},{1,0},{1,1},{1,2},{2,2}};p5s=createpieces@%;showpiece[p5s,colors[[5]]]
Out[]=
In[]:=
p6={{2,0},{2,1},{2,2},{1,2},{0,2}};p6s=createpieces@%;showpiece[p6s,colors[[6]]]
Out[]=
Place pieces
Place pieces
Check that the piece can be placed in the specified position on the board.
Check that a piece can be placed in all the ways on the board.
Solve the puzzle
Solve the puzzle
Visualize the puzzle
Visualize the puzzle
Visualize the puzzle solved by backtracking.
Let’s solve the puzzle
Let’s solve the puzzle
Solve the case on 14 March.
The time it takes to solve a puzzle varies. In some cases, the puzzle can be solved in a few seconds, while in others it may take a few minutes.
You can also change the order in which the pieces are placed to obtain different solutions.
A solution with 366 days in a year
A solution with 366 days in a year
Get a solution for one leap year.
Show the solution.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
A-Puzzle-A-Day solver: shapes placement on calendar board
by Kotaro Okazaki
Wolfram Community, STAFF PICKS, March 7, 2025
https://community.wolfram.com/groups/-/m/t/3411394
by Kotaro Okazaki
Wolfram Community, STAFF PICKS, March 7, 2025
https://community.wolfram.com/groups/-/m/t/3411394