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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education