Message Boards Message Boards

[WSC19] Creating Crossword Puzzles

Posted 5 years ago

Early in the summer of 2019, I attended the Wolfram High School Summer Camp. I worked on a project for two weeks which generates a crossword with random words that the user can solve and check. In this post, I will give a general outline of my project, then go into detail about my though process, and finally show the finished product.

How it Works

My project is basically a grid of variables, with the variables containing strings. This may seem simple, but it isn't as easy at it looks. The tricky part is having the strings change to very specific things based on random data each time the user evaluates. This makes the words in the crossword random each time in order to truly generate new crosswords each time.


Initial Start

I started by simply trying to overlay two words, but that didn't work out well... enter image description here

After that attempt, I tried a completely different approach by using grid, variables, and then associations to make a primitive crossword with a few words in it.

Grid[Join[{{Black, Black, AsNwWord[1], Black, Black, 
    Black}}, {SmpWord}, 
  Table[{Black, Black, AsNwWord[n], Black, Black, Black}, {n, 
    RevAsNwWord[AsSmpWord[3]] + 1, Length[NwWord], 1}]], Frame -> All]

This made the nice output of the following: enter code here


Preparation

Firstly, I filtered out all profane words, just to be safe...

lotswords = Pick[WordData[], First /@ Values[
    KeyTake[Classify["Profanity", WordData[], "Probabilities"], 
     True]], p_ /; p < 0.5]

Then I defined functions to make associations and character lists for all of the words in the crossword.

charwordprep[Word_] := Flatten[Characters[Word]]
aswordprep[Word_] := 
 With[{wWord = Flatten[Characters[Word]]}, 
  AssociationThread[Range[Length[wWord]], wWord]]
hintwordprep[Word_] := 
 Part[Flatten[
   Part[WordData[StringDrop[StringDrop[ToString[Word], 1], -1], 
     "Definitions"], 1]], 2]
lengthwordprep[Word_] := ToString@Length[charwordprep[Word]]

After that, I made variables for hints, hint helpers, and the correct solution. Then came the really fun part: I made the actual crossword. This could be done with such little code; I was amazed beyond belief!

fillercross = Framed[Grid[Partition[
     MapIndexed[If[#1 == 1, BlackSquare, WhiteSquares[#2[[1]]]] &, 
      Flatten[pattern]], 10], Background -> Black], 
   Background -> Black];

This had an output that looked like a crossword and that the user could type into which stored the data: enter image description here I then created a variable that checked the solution that the user typed in by using a simple if statement.

solvecheck = Dynamic[If[
   StringReplace[ToString[input], "Null" -> " "] == 
    StringDrop[StringDrop[ToLowerCase[ToString[correctlist]], 1], -1],
    Style[colorize2["This is correct!", ColorData["Rainbow"]], Bold, 
    140], Style["Sorry... try again...", Bold, 40]]]

Final Input

After making all the variables and functions in preparation for this, I finally made the manipulate! The code follows:

Framed[Manipulate[
  Column[{
    Style["Crossword Creator!", Bold, 50],
    "",
    "",
    "Please fill the generated crossword.",
    "You can type in the words, but make sure to click on each box and
insert only one letter per box.", 
    "Fill the crossword with words which have the following HINTS: ",
    "",
    horizhintz,
    "",
    verthintz,
    "",
    HintFirstLetters,
    "",
    HintLength,
    "",
    Wordbank,
    "",
    minicross,
    "",
    fillercross,
    "",
    SolutionChecker,
    "",
    Answers ,
    "",
    Style["Thank you for playing and have a great day!" , 50, 
     Italic]}],
  {HintFirstLetters, {"" -> "Hide", 
    firstletters -> "Show"}}, {HintLength, {"" -> "Hide", 
    hintlength -> "Show"}}, {Wordbank, {"" -> "Hide", 
    wordbank -> "Show"}}, {Answers, {"" -> "Hide", 
    showanswers -> "Show"}}, {SolutionChecker, {"" -> "Not Yet", 
    solvecheck -> "Check!"}}, ImageMargins -> Large], 
 FrameMargins -> 0]

The Final Output

Here is the project's summative output:enter image description here


Reflection

Throughout the process of the development of my project, I learned a few very valuable things. I learnt that even if one sets impossible goals, with time, one will accomplish said goals. Also, I realized that hard problems can be overcome with relatively simple solutions, it's just a matter of choosing the correct approach.

I would like to thank my mentor Sylvia Haas for helping me in so many ways throughout the stressful and difficult process of making this project.

https://github.com/SimeonButtery/WSS-Template

POSTED BY: Simeon Buttery
14 Replies

That's very good! I think it would be nice to also add sound effects to the evaluation and different sounds when the game ended depending on the result, and perhaps also some musical tracks controllable by Manipulate. ..just a few ideas...But your work is very impressive!

POSTED BY: Claudio Chaib

Wow! This is a great project. Can't wait to see more from you!

POSTED BY: Dev Chheda

So good 10/10

POSTED BY: Noelle Crawford
Posted 5 years ago

Great project!

POSTED BY: Sunny Wang

Awesome Project!!!!!!!

Posted 5 years ago

Thank you so much! I really appreciate your feedback.

POSTED BY: Simeon Buttery
Posted 5 years ago

Thanks for having faith in me!

POSTED BY: Simeon Buttery
Posted 5 years ago

Thanks for the support!

POSTED BY: Simeon Buttery
Posted 5 years ago

I appreciate that thanks.

POSTED BY: Simeon Buttery
Posted 5 years ago

Thank you. I'm glad you like it.

POSTED BY: Simeon Buttery

This is cool, Simeon. My grandmother would love it.

POSTED BY: Drake Hayes
Posted 5 years ago

Thats amazing. Hopefully she uses it often!

POSTED BY: Simeon Buttery
Posted 5 years ago

Awesome project! :)

POSTED BY: Lena Libon

Well done Simeon! Your project can be an excellent demonstration in Wolfram Demonstration Project. You have developed couple of functions that are suitable for Wolfram Function Repository, too. Looking forward to seeing your demo in WDP and fun/cool functions in WFR.

POSTED BY: Mohammad Bahrami
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract