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
# Put your answers here! |
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
@ones = {1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", | |
6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", | |
11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen", | |
15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen"} | |
@tens = {10 => "ten", 20 => "twenty", 30 => "thirty",40 => "forty", 50 => "fifty", | |
60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"} |
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
# Put your answers here! |
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
def random_motd | |
file_reader = File.new("motd_list.txt", "r") | |
count = 0 | |
file_reader.each do |line| | |
count += 1 | |
if Random.rand(count) == 0 | |
motd = file_reader.readline | |
end | |
end |
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
class Fleet | |
def initialize | |
@a_fleet = [] | |
end | |
def add_car(car) | |
if car.class.to_s != "Car" | |
puts "Not a car..." | |
end | |
@a_fleet << car |
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
class __GameState: | |
ALL_STATES = {} | |
def __init__(self, value, prettyStr): | |
self.value = value | |
self.prettyStr = prettyStr | |
GameState.ALL_STATES[self.value] = self | |
def invert(self): | |
return GameState.ALL_STATES[ 2 - self.value ] | |
def __cmp__(self, other): | |
return self.value - other.value |
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
http://blog.sandbochs.com | |
# The hash method produces a different value | |
# every time you load up ruby | |
# because it is based off of the object_id | |
1.hash => 3843363811812838534 | |
num = 1 | |
num.hash => 3843363811812838534 | |
# Strings override Object's hash method | |
# The hash function is based on the characters in the string |
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
def filter(ll, val) | |
fake_ll = Pair.new(424242, ll) | |
previous = fake_ll | |
while ll != nil | |
if ll.a == val | |
previous.b = ll.b | |
else | |
previous = ll | |
end |
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
# Beer song with a little RUBY style refactoring. | |
# A space should be put after the # character to denote a written comment, | |
# so people don't get confused with commented out code (no space). | |
def beer_song(num) | |
num.downto(1) do |count| | |
puts "#{count} #{pluralize_bottle(count)} of beer on the wall, #{count} #{pluralize_bottle(count)} of beer." | |
puts "Take one down and pass it around, #{count - 1} #{pluralize_bottle(count - 1)} of beer on the wall." | |
end | |
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
class Board | |
def initialize | |
@ships = self.reset_board # perhaps this needs a better name | |
end | |
def self.reset_board | |
#returns an array of new ships | |
end | |
OlderNewer