Fork on GitHub

Word Search

Easily create a 2D and 3D word searches of any size given a csv of words



Install

Add word_search to your Gemfile and bundle install:

gem "word_search"

Alternatively, you can install the gem from rubygems.org and require it in your script:

gem install word_search



Quick Start

Using the supplied Generator class you can be up and running in a couple lines:

require "word_search"

# You can also add another param, z, to get a 3D word search
generator = WordSearch::Generator.new("words.csv", 5, 5)
# Calling #perform will place the words and fill the empty spots
# with random letters
generator.perform
# Call #print to write the word search to a file
generator.print("word_search")



Plane

You can load up a word search from a file and have access to a couple helpful utilites

require "word_search"

plane = WordSearch::Plane.make_from_file("word_search")
# To find the max of x or y
plane.x
=> 5
plane.y
=> 5
# When a plane is generated, all positions by letter are
# cataloged into a hash for quick searching.
plane.catalog
=> {"j"=> [Point @letter="j", @x=0, @y=0>],
    "r"=> [Point @letter="r", @x=1, @y=0>]}
# To get all possible traversable directions around a point
plane.directions.to_h
=> { N: [0, 1], NE: [1, 1], E: [1, 0], SE: [1, -1], S: [0, -1],
     SW: [-1, -1], W: [-1, 0], NW: [-1, 1] }
# To print the plane to the screen
plane.pto_s
nvqgy
uhsit
zqloh
muudd
himyj


Solver

You can benchmark and check if your solution works by using the Solver class. Your script should be an executable ruby script that writes the location of each letter to a file in the following format and returns the file path. It should also be able to accept command line arguments for the plane file and the words file, in that order.

h [4, 9]
e [5, 9]
l [6, 9]
l [7, 9]
o [8, 9]
---
b [6, 8]
y [7, 7]
e [8, 6]

require "word_search"

plane = WordSearch::Solver.new(
  "path/to/script", "path/to/word/bank", "path/to/word/search"
)
solver.perform
=> Benchmark::Tms:0x007fd722cc6b58 @cstime=0.07,
    @cutime=0.44, @label="", @real=0.5259899999946356,
    @stime=0.0, @total=0.51, @utime=0.0
# If your script fails or is incorrect a message will appear instead
# of the benchmark.