Cody

Problem 46746. Volume of a truncated cube

Solution 3193986

Submitted on 13 Oct 2020 by Tim
• Size: 26
• This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
h1 = abs(randn); % cube h2 = sqrt(3)*h1 + abs(randn); assert(abs(TruncatedCube(h1,h2) - 8*h1^3) < 1e-6);

2   Pass
h1 = abs(randn); % cuboctahedron h2 = 2*sqrt(3)/3*h1 - abs(randn); assert(abs(TruncatedCube(h1,h2) - (20/3)*h1^3) < 1e-6);

3   Pass
assert(abs(TruncatedCube(4,3*sqrt(3)) - 476) < 1e-6);

4   Pass
assert(abs(TruncatedCube(5,4*sqrt(3)) - 964) < 1e-6);

5   Pass
assert(abs(TruncatedCube(6,5*sqrt(3)) - 1692) < 1e-6);

6   Pass
assert(abs(TruncatedCube(7,5*sqrt(3)) - 2456) < 1e-6); assert(abs(TruncatedCube(7,6*sqrt(3)) - 2708) < 1e-6);

7   Pass
assert(abs(TruncatedCube(8,6*sqrt(3)) - 3808) < 1e-6); assert(abs(TruncatedCube(8,7*sqrt(3)) - 4060) < 1e-6);

8   Pass
switch randi(4) case 1, assert(abs(TruncatedCube(9,7*sqrt(3)) - 5544) < 1e-6); case 2, assert(abs(TruncatedCube(10,8*sqrt(3)) - 7712) < 1e-6); case 3, assert(abs(TruncatedCube(11,8*sqrt(3)) - 9676) < 1e-6); case 4, assert(abs(TruncatedCube(12,9*sqrt(3)) - 12852) < 1e-6); end

9   Pass
str = fileread('TruncatedCube.m'); % sorry, no regexp hacks :-) assert(isempty(regexp(str,'regexp')));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!