Skip to content

Instantly share code, notes, and snippets.

View awhit012's full-sized avatar

Alex White awhit012

View GitHub Profile
@awhit012
awhit012 / alex_basic_horspool.rb
Last active August 29, 2015 14:13
More basic version of Horspool pattern matching algorithm, that jump uses a simplified version of the bad character table, in ruby.
#First iteration moving towards Harspool algorithm simply jumps forward by
# pattern_length if char not in pattern is found
# function accepts a string and a pattern and returns the index in the string where
# the pattern first occurs, or "not found"
def brute_search_2 string, pattern
pattern_length = pattern.length
bad_match_table = Hash.new
# Generates hash table with keys as all chars in pattern, and values as true
@awhit012
awhit012 / alex_brute_force_right_to_left.rb
Last active August 29, 2015 14:13
A brute force pattern matching algorithm that works right to left on the pattern, in ruby
#Brute Force Right to Left
# Function accepts a string and a pattern to find in that string
def brute_search_2 string, pattern
pattern_length = pattern.length
# Iterate through the string starting at string[pattern_length-1]
# We are starting there because we are looking for matches in the pattern starting
# at the last char.
for string_index in (pattern_length - 1 ... string.length)
match_count = 0
@awhit012
awhit012 / alex_brute_force_pattern_match.rb
Last active August 29, 2015 14:13
A brute force pattern matching algorithm in ruby
# Brute Force
# Takes a string and a pattern and returns the index of the pattern in the string,
# or returns "not found"
def brute_search string, pattern
pattern_length = pattern.length
for string_index in (0... string.length)
match_count = 0
loop do
# if a non-match is found, then break.
@awhit012
awhit012 / rail_fence_cypher
Created January 10, 2015 00:15
Ruby implementation of the old school Rail Fence Cypher, encrypts and decrypts using 2, 3 or 4 rows.
class Rail_Fence_Cipher
def initialize instruction, number, text
@letter_array = text.split("")
@text_length = text.length
@number = number
case instruction
when "encrypt"
encrypt
@awhit012
awhit012 / volumes_to_shapes
Created January 8, 2015 21:55
Simple Ruby program that accepts a volume in cubic meters and gives the dimensions of shapes that contain that volume
class Volume_To_Shapes
def initialize volume_input
@volume_input = volume_input
@height = cube_root @volume_input
get_cube_dimensions
get_sphere_dimensions
get_cylinder_dimensions
get_cone_dimensions
end
@awhit012
awhit012 / Alex_Boyer-Moore
Last active August 29, 2015 14:09
Boyer-Moore
# big text for timed tests
big_text = "The RSVP Hello message exchange was introduced in [RFC3209]. The
usage of RSVP Hello has been extended in [RFC3473] to support RSVP
Graceful Restart (GR) procedures.
More specifically, [RFC3473] specifies the use of the RSVP Hello
messages for GR procedures for Generalized MPLS (GMPLS). GMPLS
introduces the notion of control plane and data plane separation. In
other words, in GMPLS networks, the control plane information is
carried over a control network whose end-points are IP capable and
that may be physically or logically disjoint from the data bearer