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
=begin | |
Write a function, largest_component, that takes in the adjacency list of an undirected graph. | |
The function should return the size of the largest connected component in the graph. | |
5 | |
| \ | |
| \ | |
1-- 0 -- 8 | |
4 -- 2 | |
\ / |
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
=begin | |
Write a function, connected_components_count, that takes in the adjacency list of an undirected graph. | |
The function should return the number of connected components within the graph. | |
=end | |
# 1 - 2 | |
# 4 | |
# | | |
# 5 -- 6 -- 8 | |
# | | |
# 7 |
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
=begin | |
Write a function, undirected_path, that takes in a list of edges for an undirected graph and two nodes (node_A, node_B). | |
The function should return a boolean indicating whether or not there exists a path between node_A and node_B. | |
=end | |
edges = [ | |
['i', 'j'], | |
['k', 'i'], | |
['m', 'k'], | |
['k', 'l'], |
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
=begin | |
Write a function, has_path, that takes in a dictionary representing the adjacency list of a directed acyclic graph and two nodes (src, dst). | |
The function should return a boolean indicating whether or not there exists a directed path between the source and destination nodes. | |
=end | |
graph = { | |
'f' => ['g', 'i'], | |
'g' => ['h'], | |
'h' => [], | |
'i' => ['g', 'k'], |
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
(https://[^*,]+) |
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
module BSON | |
class ObjectId | |
def to_json(*args) | |
to_s.to_json | |
end | |
def as_json(*args) | |
to_s.as_json | |
end | |
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
require 'spec_helper' | |
describe KV do | |
describe '#set' do | |
it 'assigns a value to the instance variable hash' do | |
kv = KV.new | |
kv.set('foo', 'bar') | |
expect(kv.hash['foo'][Time.now.to_i]).to eq('bar') | |
end | |
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
Dir[File.dirname(__FILE__) + '/application/*.rb'].each { |file| require file } | |
class KV | |
attr_reader :hash | |
def initialize | |
@hash = Hash.new { |h, k| h[k] = {} } | |
end | |
def set(key, value) | |
@hash[key][Time.now.to_i] = value |
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
class Attachment < ActiveRecord::Base | |
mount_uploader :attachment, AttachmentUploader | |
# Associations | |
belongs_to :attached_item, polymorphic: true | |
# Validations | |
validates_presence_of :attachment |
NewerOlder