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 leap_year?(year) | |
if year % 4 == 0 && year % 100 != 0 | |
year == true | |
elsif year % 400 == 0 | |
year = true | |
else | |
year = false | |
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 translate_into_pig_latin(word1) | |
vowels = ["a","e","i","o","u"] | |
consonants = ["q","w","r","t","y","p","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"] | |
if vowels.include?(word1[0]) | |
word1 << "ay" | |
else | |
if word1[0..1] == "qu" | |
word1[2..word1.length] << "qu" << "ay" | |
elsif consonants.include?(word1[0]) && consonants.include?(word1[1]) && consonants.include?(word1[2]) | |
word1[3..word1.length] << word1[0..2] << "ay" |
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 triangle(number1, number2, number3) | |
if number1 > number2 + number3 || number2 > number1 + number3 || number3 > number1 + number2 | |
"This is not a triangle" | |
else | |
if number1 == number2 && number2 == number3 | |
"You have got yourself an equalateral triangle. You should try and be more creative." | |
elsif number1 == number2 || number1 == number3 || number2 == number3 | |
'This is an isosceles triangle. So you got that there going for you.' | |
elsif number1 != number2 && number2 != number3 && number3 != number1 | |
'Oh snap! That is a scalene' |
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
#defining the method and argument | |
def factorial(number1) | |
#string exception | |
if number1.kind_of? String | |
"Enter a number, smartass." | |
#array exception | |
elsif number1.kind_of? Array | |
"Just one number buddy." | |
#negative numbers exception | |
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
def title_case(sentence1) | |
if sentence1.kind_of? String | |
sentence1 = sentence1.downcase.split.to_a.map {|word| word.capitalize } | |
sentence1.join(" ") | |
else | |
"You should try and enter in a sentence." | |
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 Integer | |
def fibonacci | |
if self < 0 | |
"You can only use the fibonacci method with positive integers" | |
else | |
return self if (0..1).include? self | |
(self -1).fibonacci + (self - 2).fibonacci | |
end | |
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 Integer | |
def fibonacci | |
if self.kind_of? Integer | |
if self < 0 | |
"You can only use the fibonacci method with positive integers" | |
else | |
current = 0 | |
successor = 1 |
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 Fixnum | |
def in_words | |
#defining all the possible options for numbers < 1000 | |
first_twenty = { 0 => "Zero", 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 = { 2 => "Twenty", 3 => "Thirty", 4 => "Fourty", 5 => "Fifty", 6 => "Sixty", 7 => "Seventy", 8 => "Eighty", | |
9 => "Ninety" } | |
if ((self < 20) && (self.is_a? Integer)) | |
first_twenty[self] # |
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 Fixnum | |
def in_words | |
first_twenty = { "0" => "Zero", "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 = { "2" => "Twenty", "3" => "Thirty", "4" => "Fourty", "5" => "Fifty", "6" => "Sixty", "7" => "Seventy", "8" => "Eighty", | |
"9" => "Ninety" } | |
big_number = { 3 => "-Hundred and ", 4 => "-Thousand", 5 => "-Thousand", 6 => "-Thousand", 7 => "-Million", 8 => "-Million", 9 => "-Million", 10 => "-Billion", 11 => "-Billion", 12 => "-Billion", | |
13 => "-Trillion", 14 => "-Trillion", 15 => "-Trillion" } | |
number_string = self.to_s |
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 | |
attr_accessor :sides | |
def initialize(number) | |
@number = number | |
end | |
def roll | |
rand(1..@number) | |
end |
OlderNewer