Computer Science, asked by pooja60511, 13 hours ago

2. Purchasing SuppliesA manufacturer purchases fragile components thatmust be shipped using expensive containers. Themanufacturer agrees to provide customers with afree container of components for returning acertain number of containers. Determine themaximum number of containers a customer canreceive given a budget, the cost per container, andthe number of empty containers that must bereturned for a free container. Assume eachcontainer is immediately emptied and returned forcredit.​

Answers

Answered by shilpa85475
7

Input: n=4, cost=1, m=2

Start with a budget n = 4 units of currency to buy containers at cost = 1 unit each.

The number of empty containers to return for a free full container is m=2. First, buy 4 containers with the entire budget.

Turn in those 4 containers for 2 more containers.

Turn in those 2 containers for one more.

At this point, there are not enough funds or containers to receive another. In total, 4 +2+1 - 7 containers were obtained.

Explanation:

function p(unit_cost, budget, return_on_count)

{

   

   const initial_containers = budget/unit_cost

   let containers_count = initial_containers

   let remaining_containers = initial_containers

   

   while(remaining_containers > 0 && remaining_containers >= return_on_count ) {

       new_from_return = Math.floor(remaining_containers/return_on_count)

       containers_count+=new_from_return

       remaining_containers = new_from_return + (remaining_containers%return_on_count)

   }

   

   return containers_count

}

const unit_cost = 1

const budget = 4

const return_on_count = 2

console.log(p(unit_cost, budget, return_on_count))

console.log(p(2, 10, 5))

console.log(p(2, 6, 2))

Answered by vinothvin2000
0

Answer:

hi hvngh fhfgh

ghgg

gjgg

kjjk

juthv

Similar questions