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
#takes a dollar ammount and return the number of purchased bottles plus the maximum number of bottles possible with recyling | |
def total_bottles_from_purchase(amt) | |
amt = amt / 2 #get the number of purchased bottles | |
#Track the bottles, and caps not redeemed. Track the number of purchased, and free bottles recieved | |
tracker = {bottles:amt,caps:amt,purchased:amt,free:0} | |
while (tracker[:bottles] >= 2) || (tracker[:caps] >= 4) | |
#get the number of new free bottles from recycling | |
free = tracker[:bottles] / 2 | |
free += tracker[:caps] / 4 | |
#remove reedemed bottles and caps |
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
@ids = [[1,'I'],[5,'V'],[10,'X'],[50,'L'],[100,'C'],[500,'D'],[1000,'M']] | |
def to_roman(num) | |
str = '' | |
@ids.reverse.each { |id| | |
until num / id[0] == 0 | |
str += id[1] | |
num -= id[0] | |
end | |
if num == id[0]-1 && check[0] != 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
def count_letters(letter) | |
hash = Hash.new { |hash,key| hash[key] = [] } | |
letter.split("").each_with_index() { |x,i| | |
hash[x] << i | |
} | |
hash | |
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 mergesort(array) | |
if array.count <= 1 | |
return array #Sorted! | |
end | |
half = array.count / 2 | |
a = mergesort(array.slice(0,half)) | |
b = mergesort(array.slice(half,array.count - half)) | |
array = [] #Empty it to start sortinng |
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 mergesort(array) | |
if array.count <= 1 | |
return array #Sorted! | |
end | |
half = array.count / 2 | |
a = mergesort(array.slice(0,half)) | |
b = mergesort(array.slice(half,array.count - half)) | |
array = [] #Empty it to start sortinng |
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 cost(length,width,colors) | |
x = length * width; | |
if colors > 2 | |
x += colors * 15 | |
else | |
x += colors * 10 | |
end | |
return x * 1.15 | |
end |
NewerOlder