This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# HackerRank - Rod Cutting | |
# | |
# Given an array with the lengths of various metal rods, repeatedly perform the following: | |
# | |
# 1. Count the number of rods. | |
# 2. Find the rod(s) with the shortest length. | |
# 3. Discard any rod of that length. | |
# 4. Cut that shortest length from each of the longer rods. These are offcuts. | |
# 5. Discard all offcuts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# HackerRank - Cutting Metal Surplus | |
# | |
# The owner of a metal rod factory has a surplus of rods of arbitrary lengths. A local contractor offers to buy any of the factory's | |
# surplus as long as all the rods have the same exact integer length, referred to as saleLength. The factory owner can increase the | |
# number of sellable rods by cutting each rod zero or more times, but each cut has a cost denoted by costPerCut. After all cuts have | |
# been made, any leftover rods having a length other than saleLength must be discarded for no profit. The factory owner's total profit | |
# for the sale is calculated as: | |
# | |
# totalProfit = totalUniformRods × saleLength × salePrice − totalCuts × costPerCut |