Top Level Namespace

Defined in:

Constant Summary

NPATTERNS = 2 ** 10
STRLEN = 2 ** 10

Method Summary

Method Detail

def board_string(queens) #

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.


[View source]
def check(queens : Array(Int32)) : Bool #

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.


[View source]
def find_solutions(n_queens : Int) : Array(Array(Int32)) #

Identifies all solutions of an n-queens problem given n.


[View source]
def foo(arr) #

Print out all indices and elements of arr, return size of arr.


[View source]
def foo : Tuple(Int32, Int32) #

Overload foo with zero arguments; returns a tuple of Int32s.


[View source]
def 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.


[View source]
def hash_search(doc : String, patterns : Array(String)) #

[View source]
def print_all(solutions : Array(Array(Int32))) : Nil #

Prints all solutions to a given n-queens problem.


[View source]
def search_brute_force(doc : String, patterns : Array(String)) #

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.


[View source]
def 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. 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.


[View source]