This file contains 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
/**************************************************************** | |
Adam Lum | |
01/05/2013 | |
Coding for Interviews on Linked Lists | |
http://codingforinterviews.com | |
Implement a simple singly-linked list data structure. | |
Write a function to remove a list's 3rd from last element. |
This file contains 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
/**************************************************************** | |
Adam Lum | |
12/28/2012 | |
Coding for Interviews on Merge Sort | |
http://codingforinterviews.com | |
Write a function that merges an array of already sorted arrays, | |
producing one large, still sorted array. | |
This file contains 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
/**************************************************************** | |
Adam Lum | |
12/17/2012 | |
Coding for Interviews on Binary Search Trees | |
http://codingforinterviews.com | |
Write a function that returns whether a given binary tree | |
is a valid binary search tree. | |
This file contains 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
# Adam Lum's solution to RPCFN #8 | |
# http://rubylearning.com/blog/2010/04/07/rpcfn-xml-transformer-8/ | |
require 'rubygems' | |
require 'hpricot' | |
require 'rexml/document' | |
include REXML | |
# Get the source file(s) via the command line argument, didn't see anything | |
# in the challenge instructions detailing this step. |
This file contains 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
# Adam Lum's solution to RPCFN #6 | |
# http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/ | |
# Definitely not the most elegant, efficient, or Computer Science-y | |
# way to handle this challenge, but it's _a_ solution to these small sets. | |
# (For the sake of my code, hopefully the hypothetical t-shirt printing | |
# company in the problem never owns more than 4 machines) :) | |
class FairDistribution | |
This file contains 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
# Adam Lum's solution to RPCFN #4 | |
# http://rubylearning.com/blog/2009/11/26/rpcfn-rubyfun-4/ | |
class Polynomial | |
attr_accessor :coefficient_array | |
def initialize(in_coefficient_array) | |
if (in_coefficient_array.size < 2) | |
raise ArgumentError, "Need at least 2 coefficients." | |
end | |
@coefficient_array = in_coefficient_array |
This file contains 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
# Adam Lum's solution for RPCFN #3 | |
# http://rubylearning.com/blog/2009/10/30/rpcfn-short-circuit-3/ | |
INFINITY = 1 << 64 | |
def dijkstra (graph, start, destination) | |
# Initialize | |
nodes = [] | |
graph.each do |c| | |
nodes << c[0] |
This file contains 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
# Adam Lum's solution to RPCFN #2 | |
# http://rubylearning.com/blog/2009/10/08/rpcfn-average-arrival-time-for-a-flight-2/ | |
require 'time' | |
SECONDS_TO_CHECK_FOR = 10800 # Assuming 3 hours is a decent difference check | |
SECONDS_IN_DAY = 86400 | |
def average_time_of_day(times) | |
count_greater = 0 |
This file contains 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
# Adam Lum's solution to RPCFN #5 | |
# http://rubylearning.com/blog/2009/12/27/rpcfn-mazes-5/ | |
class Maze | |
attr_accessor :maze_array, :start_point, :end_point | |
def initialize(in_maze) | |
@start_point = [] | |
@end_point = [] | |
@maze_array = in_maze.split("\n") | |
(0..@maze_array.size - 1).each do |i| |
This file contains 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
# Adam Lum's solution for RPCFN #1 | |
# http://rubylearning.com/blog/2009/09/24/rpcfn-shift-subtitle-1/ | |
require 'optparse' | |
# Get the command line arguments | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: shift_subtitle.rb [options] input_file output_file" | |
opts.on("--operation [OPERATION]") do |o| |