Cody

# Problem 46746. Volume of a truncated cube

Solution 3199161

Submitted on 13 Oct 2020 by Giovanni Mottola
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);

s = 1.7321 V = 206.0117

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);

s = 1.7321 V = 5.7597 h2 = 1.0349 V = 4.7998

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

s = 1.7321 V = 512 h2 = 5.1962 V = 476.0000

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

s = 1.7321 V = 1000 h2 = 6.9282 V = 964

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

s = 1.7321 V = 1728 h2 = 8.6603 V = 1692

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

s = 1.7321 V = 2744 h2 = 8.6603 V = 2456 s = 1.7321 V = 2744 h2 = 10.3923 V = 2708

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

s = 1.7321 V = 4096 h2 = 10.3923 V = 3.8080e+03 s = 1.7321 V = 4096 h2 = 12.1244 V = 4060

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

s = 1.7321 V = 13824 h2 = 15.5885 V = 12852

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!