- mathspp insider đđ
- Posts
- Graphs saved the Ten Queens
Graphs saved the Ten Queens
Hey there, đ How is your Python going? In this Mathspp Insider đđ email weâll talk about how I helped the Ten Queens with their conundrum. | ![]() |
I pressed Enter
and waited nervously for a second.
The number 724
was printed in the REPL below my function call:
>>> queens(10)
724
After a split second Queen #3 shouted âBRILLIANT!â. Her enthusiasm was welcome! But there really was no need to shout so close to my earsâŚ
Queen #7 wasnât so easily impressed. âHow can we know this is correct?â.
I proceeded to explain:
âThe problem isnât that difficult. It may sound difficult⌠But it is not. Iâve solved many different problems like this one in my bootcamp. Seeââ
Queen #7 silenced me with her hand.
âIf you have solved different problems how can they be like this one?â
I smiled. It was an excellent question. But a simple question. A question coming from someone who hasnât solved many problems before. A question from someone who doesnât do programming.
âTo solve a problem you need to look beyond the words used to describe the problem.â
âExplain. Please.â Queen #7 was starting to show her impatience.
âYou explained what you needed when we talked before. The ten of you wanted to be distributed on a board without clashing with each other.
After our conversation I had to think for a bit... And then the EUREKA moment struck.
Experience told me this was a problem I could solve with a graph searching algorithm. Experience that I obtained from solving problems like the ones from my bootcamp.
I have solved so many graph searching problems that I could have written the code with my eyes closed.
I didnât do it because I wanted to avoid typos. But I could have.â
Queen #7 raised her eyebrow. My words were rubbing her the wrong way. I decided to correct course:
âI donât mean that in an arrogant way. Let me put it another way.
Youâve been queen for many years. I am certain there are recurring problems your people need help with. â Queen #7 nodded â Arenât recurring problems easier to solve?â
Queen #7 nodded again: âWhenever a bishop and a knight waltz in here I know whatâs coming. Itâs always the bishop that envies the knight or vice-versa.
Sometimes itâs the knight that wanted to move diagonally instead of in its weird way.
Sometimes itâs the bishop that wanted to ride a horse instead of having to walk.
But itâs always about envy.
Itâs always the same problem.â
âPrecisely.
Youâve been queen longer than Iâve been writing code. But Iâve practiced a lot. And this practice gave me the tools to solve this with 20 lines of code.â
Queen #7 smiled. I think. Itâs hard to tell.
She then concluded: âVery well. Now I understand why you say this was like other different problems youâve solved.
Walk me through your 20 lines of code.â
And thatâs what I did.
I started explaining my 20 lines of code.
A couple of minutes later Queen #7 was satisfied.
She waved her hand and four pawns walked in.
They carried a beautiful chest with intricate engravings filled with gold coins.
I was puzzled and turned to Queen #7.
Queen #7 was definitely smiling.
âPayment for your help.â
If you want, you can see the code I showed the queen.
Hereâs a link to the 20 lines of code that solves the âten queens problemâ.
â ď¸ Today I tried a different email format.
Use the poll below and / or reply to this email to let me know what you thought of it.
đđ How was this email? |