This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Meant to work with strings as keys. | |
class MyHash | |
def initialize(size: 100) | |
@size = size | |
@hash = Array.new(size) | |
end | |
attr_accessor :hash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Meant for strings consisting of English characters. | |
class TrieNode | |
attr_accessor :terminal, :character | |
def initialize(character: "", terminal: false) | |
@character = character | |
@terminal = terminal | |
@children = [] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Solver for the game of Set. | |
# | |
class Card | |
# Constants deriving from the rules of the game | |
COLORS = ["red", "blue", "green"] | |
SHAPES = ["circle", "square", "triangle"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementing a queue for algorithm study group. | |
class Queue | |
def initialize | |
@front = 0 | |
@back = 0 | |
@items = [nil, nil, nil, nil] | |
@num_items = 0 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementing a stack for algorithm study group. | |
# Can't use pop, <<, +, or any Ruby methods that would defeat the purpose of this exercise. | |
class Stack | |
def initialize | |
@bottom = 3 # zero-indexed | |
@top = 3 # zero-indexed | |
@items = [nil,nil,nil,nil] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Recursive fibonacci | |
var fib_recur = function (n) { | |
if (n == 0) return 0 ; | |
if (n == 1) return 1 ; | |
return fib_recur(n-1) + fib_recur(n-2) ; | |
} ; | |
//Recursive fibonacci with memoization (but without the Y-Combinator) | |
var fibonacci = (function ( ) { | |
var memo = [0, 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Y combinator | |
function Y(f) { | |
return ( | |
(function (x) { | |
return f(function (v) { return x(x)(v); }); }) | |
(function (x) { | |
return f(function (v) { return x(x)(v); }); }) | |
); | |
} |