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 Anagram | |
def initialize(anagram) | |
@anagram = anagram | |
end | |
def match(words) | |
words.select do |word| | |
is_anagram?(word) | |
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
CREATE TABLE projects( | |
id INTEGER, | |
title TEXT, | |
category_id INTEGER, | |
funding_goal INTEGER, | |
start_date INTEGER, | |
end_date INTEGER | |
); | |
CREATE TABLE categories( |
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 'pp' | |
class Array | |
def version_sort | |
version_sorted = [] | |
versions = self.collect do |filename| | |
filename =~ /^foo-(.*)\.ext$/ | |
versions = $1.split('.') | |
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_relative './song_library.rb' | |
def jukebox(command) | |
if command.downcase == "list" | |
list_library | |
else | |
parse_command(command) | |
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
pigeon_data = { | |
:color => { | |
:purple => ["Theo", "Peter Jr.", "Lucky"], | |
:grey => ["Theo", "Peter Jr.", "Ms .K"], | |
:white => ["Queenie", "Andrew", "Ms .K", "Alex"], | |
:brown => ["Queenie", "Alex"] | |
}, | |
:gender => { | |
:male => ["Alex", "Theo", "Peter Jr.", "Andrew", "Lucky"], | |
:female => ["Queenie", "Ms .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
require 'json' | |
require 'rest_client' | |
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json')) | |
reddit_hash["data"]["children"].select! { |story| story["data"]["subreddit"] != "gaming" } | |
puts "<html>" | |
puts "<head>" | |
puts "</head>" |
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
# create a method called create_groups that, given an array of student names, | |
# a group size, and a number of groups, will return an array of groups of | |
# of students with no student in adjacent groups | |
def create_groups(student_names, group_size, number_of_groups) | |
student_names.shuffle! | |
groups = [] | |
number_of_groups.times do | |
group = [] |
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
# tower_of_hanoi.rb | |
a = [1,2,3,4] | |
b = [] | |
c = [] | |
# Move the disks from one peg to another following the rules of Hanoi. | |
# | |
# number_of_disks - the total number of disks | |
# from - the starting peg |
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
def prime?(number) | |
tries = 0 | |
i = 5 | |
prime = true | |
return false if number.even? || number % 3 == 0 || number < 2 | |
while (i*i) < number | |
tries += 1 | |
prime = false and break if number % i == 0 | |
i += 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
def my_each(array) | |
i = 0 | |
while i < array.length | |
yield(array[i]) | |
i+=1 | |
end | |
array | |
end | |