Skip to content

Instantly share code, notes, and snippets.

View cody-code-wy's full-sized avatar

William Young cody-code-wy

View GitHub Profile
#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
@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
def count_letters(letter)
hash = Hash.new { |hash,key| hash[key] = [] }
letter.split("").each_with_index() { |x,i|
hash[x] << i
}
hash
end
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
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
def cost(length,width,colors)
x = length * width;
if colors > 2
x += colors * 15
else
x += colors * 10
end
return x * 1.15
end