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
# There once was a wise servant who saved the life of a prince. The king promised to pay whatever the servant could dream up. Knowing that the king loved chess, the servant told the king he would like to have grains of wheat. One grain on the first square of a chess board. Two grains on the next. Four on the third, and so on. | |
# There are 64 squares on a chessboard. | |
# Write a program that shows | |
# - how many grains were on each square, and | |
# - the total number of grains | |
# ## For bonus points |
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 Person | |
attr_accessor :name, :birthday, :hair_color, :eye_color, :height, :weight, | |
:handed, :complexion, :t_shirt_size, :wrist_size, :glove_size, | |
:pant_length, :pant_width | |
def initialize(data) | |
data.each do |attrib, value| | |
self.send("#{attrib}=", value) unless !self.respond_to?(attrib.to_sym) | |
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
class TriangleError < StandardError | |
end | |
class Triangle | |
attr_accessor :a, :b, :c | |
def initialize(a, b, c) | |
@a = a | |
@b = b |
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 'simplecov' | |
SimpleCov.start | |
require 'json' | |
require 'rspec' | |
require_relative 'jukebox' | |
require_relative 'song' | |
describe Song do |
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 | |
attr_accessor :word | |
def initialize(word) | |
@word = word | |
end | |
# def match(anagram_array) | |
# anagram_array.map do |potential| |
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' | |
require 'pry' | |
require 'awesome_print' | |
require 'colorize' | |
system("clear") | |
puts("Starting up...") | |
if ARGV.first |
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
while true | |
system("clear") | |
longest_upvote = 0 | |
Post::POSTS.each do |post| | |
if post.upvotes.to_s.length > longest_upvote | |
longest_upvote = post.upvotes.to_s.length | |
end | |
end | |
Post::POSTS.each do |post| |
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 'pry' | |
require 'awesome_print' | |
######################## | |
# NYC PIGEON ORGANIZER # | |
######################## | |
# Start with the following collected data on NYC pigeons. | |
pigeon_data = { |
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' | |
require 'pry' | |
require 'awesome_print' | |
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json')) | |
reddit_html = " " | |
def make_post_html(post_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
a = [1,2,3,4] | |
b = [] | |
c = [] | |
def move_disc(num_discs, from_peg, via_peg, to_peg) | |
watch_hannoi(from_peg, via_peg, to_peg) | |
sleep(1) | |
if num_discs == 1 | |
to_peg.unshift(from_peg.shift) | |
else |