Determining the Label of a Stone Block Based on Size and Weight

MD Jamil Kashem Porosh
3 min readSep 23, 2023

--

Stone blocks come in various sizes and weights, and it can be useful to categorize them based on their dimensions and mass. In this blog post, we’ll explore a problem where we need to determine the label of a stone block given its length, width, height, and mass. We’ll discuss the criteria for labeling the block as “Large,” “Big,” or a combination of both, and provide code examples in JavaScript and Python to solve the problem.

Problem Statement:

Given the integers representing the length (L), width (W), height (H), and mass (M) of a stone block, we need to determine its label based on the following criteria:

  1. The block is labeled as “Large” if any of its dimensions (L, W, H) is greater than or equal to 104.
  2. Alternatively, the block is labeled as “Large” if the volume of the block (L * W * H) is greater than or equal to 109.
  3. If the mass (M) of the block is greater than or equal to 100, it is labeled as “Big.”
  4. If a block satisfies both the “Large” and “Big” conditions, it is labeled as “Both.”
  5. If a block satisfies neither the “Large” nor the “Big” condition, it is labeled as “Neither.”
  6. If a block is “Large” but not “Big,” it is labeled as “Large.”
  7. If a block is “Big” but not “Large,” it is labeled as “Big.”

Example:

Let’s consider an example to illustrate the problem. Suppose we have a stone block with the dimensions I = 100, W = 50, H = 70, and mass M = 500. We need to determine its label.

Solution:

To solve this problem, we can follow a straightforward approach:

Calculate the volume of the stone block by multiplying its length (I), width (W), and height (H): volume = I * W * H.
Check if any of the dimensions (I, W, H) is greater than or equal to 104, or if the volume is greater than or equal to 109.
If the above condition is true, check if the mass (M) is greater than or equal to 100.
Based on the conditions, assign the appropriate label to the stone block: “Both,” “Large,” “Big,” or “Neither.”

Code Examples:
Here’s an implementation of the problem in JavaScript:

function getBlockLabel(I, w, h, m) {
const volume = I * w * h;

if (I >= 104 || w >= 104 || h >= 104 || volume >= 10 ** 9) {
if (m >= 100) {
return "Both";
} else {
return "Large";
}
} else if (m >= 100) {
return "Big";
} else {
return "Neither";
}
}

// Example usage
const label = getBlockLabel(100, 50, 70, 500);
console.log(label); // Output: "Big"

And here’s the equivalent implementation in Python:

def get_block_label(I, w, h, m):
volume = I * w * h

if I >= 104 or w >= 104 or h >= 104 or volume >= 10**9:
if m >= 100:
return "Both"
else:
return "Large"
elif m >= 100:
return "Big"
else:
return "Neither"

# Example usage
label = get_block_label(100, 50, 70, 500)
print(label) # Output: "Big"

Conclusion:

In this blog post, we addressed the problem of determining the label of a stone block based on its size and weight. We discussed the criteria for labeling the block as “Large,” “Big,” or a combination of both. We provided code examples in JavaScript and Python to solve the problem, illustrating the step-by-step approach. By applying these solutions, you can easily categorize stone blocks and automate the labeling process based on their dimensions and mass.

Note::

👋 Hey there! If you have any burning questions or just want to say hi, don’t be shy — I’m only a message away. 💬 You can reach me at jamilkashem@zoho.com.

🤝 By the way, I think we share the same interest in software engineering — let’s connect on LinkedIn! 💻

--

--

MD Jamil Kashem Porosh

Software Engineer | 📝 Tech Blogger | React.js, React Native, JavaScript, Go, Python. (✉️ jamilkashem@zoho.com)