thisishaa.blogg.se

Letter soup generator
Letter soup generator








module WordSearch class Grid attr_reader :rows, :columns, :size def initialize ( rows, columns, grid = nil ), = rows, columns = * = grid || Array. This way I can represent each location as a single integer, which is cleaner than trying to juggle (row, column) tuples. Since the algorithm requires that I be able to try a word against every possible location in the grid, I chose to implement the grid as a one-dimensional array. Visually, it’s a two-dimensional grid of rows and columns: grid = WordSearch :: Grid. The first thing to do was to represent the grid itself. Once all words have been placed, fill in the unused squares with random letters.Once the word has been placed successfully, repeat from step #1.If there is no previous word, fail (because the words cannot all fit on the grid).If the word fails to fit anywhere on the grid, backtrack and try from step #2 with the previous word.Add it to a random location in the grid.The core of the algorithm (after deciding on the word list and the size of the puzzle grid) is just this: (Bonus: the letters left after finding all the words spell out one of my favorite features of Ruby…) It generates puzzles that look like this: After spending ten minutes looking online and being fairly disappointed in the quality of what we found, I decided to take a stab at writing a word search puzzle generator myself.įortunately for me it wasn’t too hard at all, though I’m sure my implementation is far from optimal.

letter soup generator

My daughter (age 11) was writing an article this week for a local student newsletter, and had the idea to include a word search puzzle.










Letter soup generator