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
module InWords | |
def in_words | |
num_array = self.to_s.split('') | |
ones_place = {"0" => "", "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five", "6" => "six", | |
"7" => "seven", "8" => "eight", "9" => "nine"} | |
final_digit_in_words = ones_place[num_array[-1]] | |
tens_place = {"0" => "", "1" => "", "2" => "twenty", "3" => "thirty", "4" => "forty", "5" => "fifty", "6" => "sixty", "7" => "seventy", "8" => "eighty", | |
"9" => "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
class Fixnum | |
def factorial | |
if self < 0 | |
raise "You can't take the factorial of a negative number." | |
elsif | |
self == 0 | |
1 | |
else | |
self * (self-1).factorial | |
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(arr=[0,1]) | |
arr[self] ||= (self-1).fibonacci(arr) + (self-2).fibonacci(arr) | |
# if arr[self].nil? | |
# arr[self] = (self-1).fibonacci(arr) + (self-2).fibonacci(arr) | |
# end | |
# arr[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 Integer | |
def fibonacci | |
first = 0 | |
last = 1 | |
(self-1).times do | |
current = first + last | |
first = last | |
last = current | |
end | |
return last |
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
module InWords | |
def magic | |
ones_array = %w{ not_called one two three four five six seven eight nine ten} | |
tens_array = %w{ not_called not_called twenty thirty forty fifty sixty seventy eighty ninety} | |
teens_array = [ "" ] + %w{ one two three four five six seven eight nine ten eleven twelve | |
thirteen fourteen fifteen sixteen seventeen eighteen nineteen} | |
# if self == 0 | |
# return "zero" | |
# 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 Calculator | |
def add(num1,num2) | |
@num1= num1 | |
@num2 = num2 | |
output("sum", num1 + num2) | |
end | |
def subtract(num1,num2) | |
@num1= num1 |
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 Dictionary | |
attr_accessor :this_dictionary | |
def initialize | |
this_dictionary = {} | |
@this_dictionary = this_dictionary | |
end | |
def entries |
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 RPN | |
attr_accessor :calculator | |
def initialize | |
@calculator = [] | |
end | |
def push(arg) |
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 RPNCalculator | |
attr_accessor :calculator, :result | |
def initialize | |
@calculator = [] | |
@result = 0 | |
end | |
def push(arg) |
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 RPNCalculator | |
attr_accessor :calculator, :result, :subtotal, :mini_array | |
def initialize | |
@calculator = [] | |
@mini_array = [] | |
@result = 0 | |
@subtotal = 0 | |
end |
OlderNewer