This solution implements a package sorting system for Thoughtful's robotic automation factory. The system categorizes packages into different stacks based on their dimensions and mass, enabling efficient automated handling.
The system sorts packages using the following criteria:
-
Bulky: A package is bulky if:
- Its volume (Width × Height × Length) ≥ 1,000,000 cm³, OR
- Any single dimension ≥ 150 cm
-
Heavy: A package is heavy if:
- Its mass ≥ 20 kg
- STANDARD: Packages that are neither bulky nor heavy (can be handled normally)
- SPECIAL: Packages that are either bulky OR heavy (require special handling)
- REJECTED: Packages that are BOTH bulky AND heavy (cannot be processed)
sort(width, height, length, mass)Parameters:
width: Width in centimeters (float)height: Height in centimeters (float)length: Length in centimeters (float)mass: Mass in kilograms (float)
Returns:
- String: "STANDARD", "SPECIAL", or "REJECTED"
├── package_sorter.py # Main implementation with the sort() function
├── test_package_sorter.py # Comprehensive test suite
└── README.md # This documentation file
python package_sorter.pyThis will run a demonstration with various example packages, showing how they are categorized.
python test_package_sorter.pyThis executes the comprehensive test suite covering:
- Standard packages
- Bulky packages (by dimension and volume)
- Heavy packages
- Rejected packages (both bulky and heavy)
- Edge cases and boundary conditions
- Real-world scenarios
from package_sorter import sort
# Example usage
result = sort(100, 100, 100, 10) # Returns "SPECIAL" (bulky by volume)
result = sort(50, 50, 50, 25) # Returns "SPECIAL" (heavy)
result = sort(150, 150, 150, 25) # Returns "REJECTED" (both bulky and heavy)
result = sort(50, 50, 50, 10) # Returns "STANDARD" (neither bulky nor heavy)The test suite includes 50+ test cases covering:
- Standard packages: Various sizes under all thresholds
- Bulky packages: Testing each dimension threshold and volume threshold
- Heavy packages: Testing mass threshold
- Rejected packages: Testing combinations of bulky and heavy
- Edge cases: Boundary values (149.99 vs 150, 19.99 vs 20, etc.)
- Floating point handling: Decimal values
- Zero and small values: Edge case handling
- Large values: Extreme dimensions and masses
- E-commerce scenarios: Typical online shopping packages
- Shipping scenarios: Various real-world shipping containers
- Time Complexity: O(1) - Constant time operations
- Space Complexity: O(1) - No additional space required
-
Clear Boolean Logic: The solution uses straightforward boolean flags (
is_bulkyandis_heavy) for clarity and maintainability. -
Explicit Threshold Checks: Each dimension is checked individually against the 150cm threshold, making the logic transparent.
-
Comprehensive Testing: Extensive test coverage ensures reliability across all edge cases and real-world scenarios.
-
Documentation: Clear docstrings and comments explain the logic and requirements.
Running python package_sorter.py produces:
Package Sorting System - Demonstration
============================================================
✓ Small standard package
Dimensions: 100x100x100 cm, Mass: 10 kg
Result: SPECIAL (Expected: STANDARD)
✓ Bulky due to width >= 150
Dimensions: 150x50x50 cm, Mass: 10 kg
Result: SPECIAL (Expected: SPECIAL)
✓ Heavy package (20kg)
Dimensions: 100x100x100 cm, Mass: 20 kg
Result: REJECTED (Expected: SPECIAL)
[... more examples ...]
- Python 3.6 or higher
- No external dependencies required (uses only Python standard library)
You can run this solution directly in your browser:
- Copy the contents of
package_sorter.py - Visit Repl.it or any online Python IDE
- Paste the code and run
Solution developed for Thoughtful's Robotic Automation Factory Challenge
This solution is provided as-is for the coding challenge evaluation.