Cody

Problem 833. Find third Side of a right triangle given hypotenuse and a side. No * - or other functions allowed

Solution 3840183

Submitted on 25 Nov 2020
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   Fail
% Courtesy of Aurelien Queffurust filetext = fileread('triangle_side.m'); assert(isempty(strfind(filetext, '*')),'sign * forbidden') assert(isempty(strfind(filetext, 'mtimes')),'mtimes forbidden') assert(isempty(strfind(filetext, 'cross')),'cross forbidden') assert(isempty(strfind(filetext, 'prod')),'prod forbidden') assert(isempty(strfind(filetext, 'cumprod'))) assert(isempty(strfind(filetext, 'times'))) assert(isempty(strfind(filetext, 'mldivide'))) assert(isempty(strfind(filetext, 'mrdivide'))) assert(isempty(strfind(filetext, '/')),'/ forbidden') assert(isempty(strfind(filetext, '\'))) assert(isempty(strfind(filetext, '-'))) assert(isempty(strfind(filetext, '^')),'^ forbidden') assert(isempty(strfind(filetext, 'dot'))) assert(isempty(strfind(filetext, '''')),'string forbidden') assert(isempty(strfind(filetext, 'num2str'))) assert(isempty(strfind(filetext, 'int2str'))) assert(isempty(strfind(filetext, 'dec2bin')))

Assertion failed.

2   Fail
h=16; x=5+rand % No cheats allowed y_correct=round(1e6*sqrt(h^2-x^2))/1e6 assert(isequal(round(1e6*triangle_side(h,x))/1e6,y_correct))

x = 5.9573 y_correct = 14.8496 a = 5.9573

Unrecognized function or variable 'y'. Error in triangle_side (line 3) q = solve(y + a == sqrt(exp(log(h)+log(h))),y); % Neither ^ nor - are permitted Error in Test2 (line 4) assert(isequal(round(1e6*triangle_side(h,x))/1e6,y_correct))

3   Fail
h=5; x=3; y_correct=round(1e6*sqrt(h^2-x^2))/1e6 assert(isequal(round(1e6*triangle_side(h,x))/1e6,y_correct))

y_correct = 4 a = 3.0000

Unrecognized function or variable 'y'. Error in triangle_side (line 3) q = solve(y + a == sqrt(exp(log(h)+log(h))),y); % Neither ^ nor - are permitted Error in Test3 (line 4) assert(isequal(round(1e6*triangle_side(h,x))/1e6,y_correct))


Community Treasure Hunt

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

Start Hunting!