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) | |
return true | |
elsif (!(year % 400 == 0) and (year % 100 == 0 and year % 4 == 0)) | |
return false | |
elsif ((year % 100 == 0 and year % 400 == 0) and !(year % 4 == 0)) | |
return true | |
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 welcome(string) | |
if (string =~ /CA(.*)/ ) | |
puts "Welcome to California" | |
else | |
puts "You should move to California" | |
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 welcome(string) | |
if (string.match("CA")) | |
puts "Welcome to California" | |
else | |
puts "You should move to California" | |
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 leap_year?(year) | |
if year % 4 == 0 | |
puts true | |
elsif year % 100 == 0 | |
puts false | |
elsif year % 100 == 0 && year % 400 == 0 | |
puts true | |
elsif year % 4 == 0 && year % 100 == 0 && !(year % 400 == 0) | |
puts false |
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
# test to see if valid triangle | |
def valid_triangle?(a, b, c) | |
if ((a == 0 or b == 0 or c == 0) or (a == nil or b == nil or c == nil)) | |
return false | |
end | |
if a + b > c | |
return true |
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) | |
array.each do |w| | |
if w % 15 == 0 | |
puts "FizzBuzz" | |
elsif w % 3 == 0 | |
puts "Fizz" | |
elsif w % 5 == 0 | |
puts "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
def has_ssn?(string) | |
if string =~ /\d{3}\W\d{2}\W\d{4}/ | |
true | |
elsif string =~ /\d{9}/ | |
true | |
else | |
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
class Vehicle | |
def powerplant(args) | |
@engine | |
@transmission | |
@drivetrain | |
end | |
def chassis(args) |
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 factorial_iterative(number) | |
until number == 1 | |
number *= number - 1 | |
number -= 1 | |
p number | |
end | |
fib_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 Die | |
attr_reader :dice, :top | |
@@dice = [['A','A','E','E','G','N'], | |
['E','L','R','T','T','Y'], | |
['A','O','O','T','T','W'], | |
['A','B','B','J','O','O'], | |
['E','H','R','T','V','W'], | |
['C','I','M','O','T','U'], |
OlderNewer