Top Level Namespace
Defined in:
Constant Summary
-
NPATTERNS =
2 ** 10
-
STRLEN =
2 ** 10
Method Summary
-
board_string(queens)
Generates a visual representation of a chessboard using unicode symbols.
-
check(queens : Array(Int32)) : Bool
If queens represents a valid solution to the n-queens problem, returns true.
-
find_solutions(n_queens : Int) : Array(Array(Int32))
Identifies all solutions of an n-queens problem given n.
-
foo(arr)
Print out all indices and elements of arr, return size of arr.
-
foo : Tuple(Int32, Int32)
Overload
foo
with zero arguments; returns a tuple of Int32s. -
generate_patterns(n_patterns, strlen, doc : String) : Array(String)
Returns an Array with n_patterns strlen-character Strings, of which one is a substring of doc and the rest are random.
- hash_search(doc : String, patterns : Array(String))
-
print_all(solutions : Array(Array(Int32))) : Nil
Prints all solutions to a given n-queens problem.
-
search_brute_force(doc : String, patterns : Array(String))
For each pattern String in patterns, iterate over doc until the first is found.
-
search_rabin_karp(doc : String, patterns : Array(String)) : Tuple(Int32 | Nil, String)
Uses the Rabin-Karp algorithm to search doc for any pattern in patterns.
Method Detail
Generates a visual representation of a chessboard using unicode symbols.
NOTE The type of queens is implicitly assumed, as is the return type
(contrast with #check
). Both ways are acceptable, but this reduces clarity.
If queens represents a valid solution to the n-queens problem, returns true. queens should be an array of n integers representing a board state.
Identifies all solutions of an n-queens problem given n.
Returns an Array with n_patterns strlen-character Strings, of which one is a substring of doc and the rest are random.
Prints all solutions to a given n-queens problem.
For each pattern String in patterns, iterate over doc until the first is found. All strings in patterns should be the same length. Returns the index and matched pattern if found, else nil.
Uses the Rabin-Karp algorithm to search doc for any pattern in patterns.
All strings in patterns should be the same length.
Much more time-efficient than #search_brute_force
for large numbers of patterns.
Returns the index and matched pattern if found, else nil.