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 is_fibonacci?(i) | |
if (i <= 3) | |
return true | |
else | |
num = [0,1,1,2,3,5] | |
(i).times do | |
num.push(num[-1]+num[-2]) | |
end | |
num | |
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 GuessingGame | |
def initialize(answer) | |
@answer=answer | |
end | |
def guess(guess) | |
@solved=false | |
if guess > @answer | |
:high | |
elsif guess < @answer |
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 Die | |
def initialize(labels) | |
@labels=labels | |
if @labels.length == 0 | |
raise ArgumentError.new("Only Die with one or more sides is allowed!") | |
else | |
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
def super_fizzbuzz(array) | |
fizzbuzzed = [] | |
array.each do |n| | |
if (n % 3 == 0) && (n % 5 == 0) | |
fizzbuzzed << "FizzBuzz" | |
elsif (n % 3 == 0) | |
fizzbuzzed << "Fizz" | |
elsif (n % 5 == 0) | |
fizzbuzzed << "Buzz" | |
else |
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 Die | |
def initialize(sides) | |
@sides=sides | |
if @sides <= 0 | |
raise ArgumentError.new("Only Die with one or more sides is allowed!") | |
else | |
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
grocery_list = {} | |
grocery_list['items'] = 'milk' | |
grocery_list['items'] = 'eggs' | |
grocery_list['items'] = 'bread' | |
grocery_list['items'] = 'eggs' | |
grocery_list.each do |c_word, word| | |
puts "#{c_word}:#{word}" |
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 fizzblam(array) | |
fizzblammed = [] | |
array.each do |n| | |
if (n %5 == 0) && (n % 7 == 0) | |
fizzblammed << "FizzBlam" | |
elsif (n % 5 == 0) | |
fizzblammed << "Fizz" | |
elsif (n % 7 == 0) | |
fizzblammed << "Blam" | |
else |
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 Array | |
def pad!(min_size, value = nil) | |
x = min_size - self.count #take the argument and subtract the count from it. | |
x.times do | |
self << value | |
end | |
self | |
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 Rectangle | |
attr_accessor :width, :height | |
def initialize(width, height) | |
@width = width | |
@height = height | |
end | |
def area | |
return area = @width * @height |
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 smallest_integer(array) | |
i=0 | |
if array.length > i | |
puts array.min | |
else | |
puts nil | |
end | |
end | |
smallest_integer([34,-456,56]) |
OlderNewer