## after
defdiscount_by_item(apple)
full_quantity =0
discount_quantity =0
full_price = apple.price
discount_price = apple.price - apple.price_plan.discount
if(apple.price_plan.limit.nil?)# if we don't have a limit
full_quantity=apple.quantity
if apple.quantity>apple.price_plan.buy_quantity # we're buying more than needed for the discount
full_quantity=apple.price_plan.buy_quantity # then we're paying full price for the buy quantity
discount_quantity=apple.quantity-full_quantity # and discounted price for all th test
endelse# how many items in each group
groups_of=apple.price_plan.limit+apple.price_plan.buy_quantity
groups=apple.quantity/groups_of
full_quantity=groups*apple.price_plan.buy_quantity
discount_quantity=groups*(groups_of-full_quantity)# if we have some left over items
if(left_overs=(apple.quantity-full_quantity+discount_quantity))>0# TODO: your homework
endend
full_quantity, full_price, discount_quantity, discount_price
end## before
defdiscount_by_item(apple)
full_qty_counter =0
disc_qty_counter =0
full_qty =0
discount_qty =0
full_price = apple.price
discount_price = apple.price - apple.price_plan.discount
if(apple.price_plan.limit >0)for i in1..apple.quantity
if(full_qty_counter >= apple.price_plan.buy_qty && disc_qty_counter <= apple.price_plan.limit)
discount_qty +=1
disc_qty_counter +=1else
full_qty +=1
full_qty_counter +=1endif(disc_qty_counter == apple.price_plan.limit)
disc_qty_counter =0
full_qty_counter =0endendelsewhile(full_qty >= apple.price_plan.buy_qty)
full_qty -=1
discount_qty +=1endendreturn full_qty, full_price, discount_qty, discount_price
end