rez - a tool for calculating material cutting.
The rez utility finds best way to cut materials of given length such way that all needed items will be created, losing minimum of materials. For details, see the manpage.
Building instructions:
Usual CMake-based build: "mkdir -p build && cd build && cmake .. && make". On non-BSD systems you'll need libbsd-dev as well.
This code definitely wanna more tests.