A hardware store is selling steel rods of various lengths. However, customers sometimes want to buy rods that the store doesn't carry. For example, if the store only carries 10cm and 30cm rods and a customer wants to buy a 25cm rod, then the order cannot be fulfilled. To boost sales, the store has come up with an idea to weld two rods together to make a longer rod. For example, if the store only carries 3cm and 5cm rods and a customer wants to buy a 8cm rod, then the order can be fulfilled by welding together 3-cm and 5-cm rods. Since rod welding can compromise the strength, the store will only weld up to TWO rods together. More precisely, this means, an order for x cm can be fulfilled if there is a single rod of length x or there are two rods (potentially of the same length) whose combined length is x. Your Task: Write a function process Orders (orders: List[int], sizes:List[int]) -> List[bool] to determine whether or not each of the given orders can be fulfilled. Here, orders is a list of positive integers, where each integer represents the length as requested by that order. sizes is a list of positive integers (not necessarily ordered from small to large) representing the individual rod lengths that this store carries. Your function must return a list of booleans, where the i-th element indicates whether or not the i -th order can be fulfilled. processOrders ([5, 12, 13, 20], [1, 2, 5, 10]) == [True, True, False, True] In the above example, the store carries rods of lengths: 1, 2, 5, 10. The order of 5-cm can be fulfilled because the store sells 5-cm rods. Also, the order of 12-cm can be fulfilled because the store combines 2-cm and 10-cm rods. The order of 13-cm cannot be fulfilled. The order of 20-cm can be fulfilled because the store welds together two 10-cm rods. Performance Expectations: We'll only test your program with 1 <= len(orders), len(sizes) <= 100 . For each function call, your function must return within 1 second.

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter17: Markov Chains
Section: Chapter Questions
Problem 12RP
icon
Related questions
Question
A hardware store is selling steel rods of various lengths. However, customers sometimes want to buy rods that the
store doesn't carry. For example, if the store only carries 10cm and 30cm rods and a customer wants to buy a 25cm
rod, then the order cannot be fulfilled. To boost sales, the store has come up with an idea to weld two rods together
to make a longer rod. For example, if the store only carries 3cm and 5cm rods and a customer wants to buy a 8cm
rod, then the order can be fulfilled by welding together 3-cm and 5-cm rods. Since rod welding can compromise the
strength, the store will only weld up to TWO rods together. More precisely, this means, an order for x cm can be
fulfilled if there is a single rod of length x or there are two rods (potentially of the same length) whose combined
length is x.
Your Task: Write a function process Orders (orders: List[int], sizes:List[int]) -> List[bool] to determine whether
or not each of the given orders can be fulfilled. Here, orders is a list of positive integers, where each integer
represents the length as requested by that order. sizes is a list of positive integers (not necessarily ordered from
small to large) representing the individual rod lengths that this store carries. Your function must return a list of
booleans, where the i-th element indicates whether or not the i -th order can be fulfilled.
processOrders ([5, 12, 13, 20], [1, 2, 5, 10])
==
[True, True, False, True]
In the above example, the store carries rods of lengths: 1, 2, 5, 10. The order of 5-cm can be fulfilled because the store
sells 5-cm rods. Also, the order of 12-cm can be fulfilled because the store combines 2-cm and 10-cm rods. The order
of 13-cm cannot be fulfilled. The order of 20-cm can be fulfilled because the store welds together two 10-cm rods.
Performance Expectations: We'll only test your program with 1 <= len(orders), len(sizes) <= 100 . For each
function call, your function must return within 1 second.
Transcribed Image Text:A hardware store is selling steel rods of various lengths. However, customers sometimes want to buy rods that the store doesn't carry. For example, if the store only carries 10cm and 30cm rods and a customer wants to buy a 25cm rod, then the order cannot be fulfilled. To boost sales, the store has come up with an idea to weld two rods together to make a longer rod. For example, if the store only carries 3cm and 5cm rods and a customer wants to buy a 8cm rod, then the order can be fulfilled by welding together 3-cm and 5-cm rods. Since rod welding can compromise the strength, the store will only weld up to TWO rods together. More precisely, this means, an order for x cm can be fulfilled if there is a single rod of length x or there are two rods (potentially of the same length) whose combined length is x. Your Task: Write a function process Orders (orders: List[int], sizes:List[int]) -> List[bool] to determine whether or not each of the given orders can be fulfilled. Here, orders is a list of positive integers, where each integer represents the length as requested by that order. sizes is a list of positive integers (not necessarily ordered from small to large) representing the individual rod lengths that this store carries. Your function must return a list of booleans, where the i-th element indicates whether or not the i -th order can be fulfilled. processOrders ([5, 12, 13, 20], [1, 2, 5, 10]) == [True, True, False, True] In the above example, the store carries rods of lengths: 1, 2, 5, 10. The order of 5-cm can be fulfilled because the store sells 5-cm rods. Also, the order of 12-cm can be fulfilled because the store combines 2-cm and 10-cm rods. The order of 13-cm cannot be fulfilled. The order of 20-cm can be fulfilled because the store welds together two 10-cm rods. Performance Expectations: We'll only test your program with 1 <= len(orders), len(sizes) <= 100 . For each function call, your function must return within 1 second.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Probability Problems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole