Cody

Problem 2635. Higher! Lower!

Solution 4005683

Submitted on 5 Dec 2020 by Michael Cappello
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
hi_bound=1024; lo_bound=1; right_answer=512; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), 512))

ans = 1

2   Pass
hi_bound=1024; lo_bound=1; right_answer=513; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), [512 768 640 576 544 528 520 516 514 513]))

ans = 1 512 512 1024 ans = 1 512 768 512 768 ans = 1 512 768 640 512 640 ans = 1 512 768 640 576 512 576 ans = 1 512 768 640 576 544 512 544 ans = 1 512 768 640 576 544 528 512 528 ans = 1 512 768 640 576 544 528 520 512 520 ans = 1 512 768 640 576 544 528 520 516 512 516 ans = 1 512 768 640 576 544 528 520 516 514 512 514 ans = 1

3   Pass
hi_bound=0; lo_bound=-16; right_answer=-3; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), [ -8 -4 -2 -3]))

ans = 1 -8 -8 0 ans = 1 -8 -4 -4 0 ans = 1 -8 -4 -2 -4 -2 ans = 1

4   Pass
hi_bound=1024; lo_bound=1; right_answer=1024; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), [512 768 896 960 992 1008 1016 1020 1022 1023 1024]))

ans = 1 512 512 1024 ans = 1 512 768 768 1024 ans = 1 512 768 896 896 1024 ans = 1 512 768 896 960 960 1024 ans = 1 512 768 896 960 992 992 1024 ans = 1 512 768 896 960 992 1008 1008 1024 ans = 1 512 768 896 960 992 1008 1016 1016 1024 ans = 1 512 768 896 960 992 1008 1016 1020 1020 1024 ans = 1 512 768 896 960 992 1008 1016 1020 1022 1022 1024 ans = 1 512 768 896 960 992 1008 1016 1020 1022 1023 1023 1024 ans = 1

5   Pass
hi_bound=2048; lo_bound=0; right_answer=0; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), [1024 512 256 128 64 32 16 8 4 2 1 0]))

ans = 1 1024 0 1024 ans = 1 1024 512 0 512 ans = 1 1024 512 256 0 256 ans = 1 1024 512 256 128 0 128 ans = 1 1024 512 256 128 64 0 64 ans = 1 1024 512 256 128 64 32 0 32 ans = 1 1024 512 256 128 64 32 16 0 16 ans = 1 1024 512 256 128 64 32 16 8 0 8 ans = 1 1024 512 256 128 64 32 16 8 4 0 4 ans = 1 1024 512 256 128 64 32 16 8 4 2 0 2 ans = 1 1024 512 256 128 64 32 16 8 4 2 1 0 1 ans = 1

6   Pass
hi_bound=65535; lo_bound=0; right_answer=1024; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), [32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1055 1039 1031 1027 1025 1024]))

ans = 1 32767 0 32767 ans = 1 32767 16383 0 16383 ans = 1 32767 16383 8191 0 8191 ans = 1 32767 16383 8191 4095 0 4095 ans = 1 32767 16383 8191 4095 2047 0 2047 ans = 1 32767 16383 8191 4095 2047 1023 1023 2047 ans = 1 32767 16383 8191 4095 2047 1023 1535 1023 1535 ans = 1 32767 16383 8191 4095 2047 1023 1535 1279 1023 1279 ans = 1 32767 16383 8191 4095 2047 1023 1535 1279 1151 1023 1151 ans = 1 32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1023 1087 ans = 1 32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1055 1023 1055 ans = 1 32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1055 1039 1023 1039 ans = 1 Columns 1 through 14 32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1055 1039 1031 1023 Column 15 1031 ans = 1 Columns 1 through 14 32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1055 1039 1031 1027 Columns 15 through 16 1023 1027 ans = 1 Columns 1 through 14 32767 16383 8191 4095 2047 1023 1535 1279 1151 1087 1055 1039 1031 1027 Columns 15 through 17 1025 1023 1025 ans = 1

7   Pass
hi_bound=1; lo_bound=0; right_answer=1; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), [0 1]))

ans = 1 0 0 1 ans = 1

Suggested Problems

More from this Author80

Community Treasure Hunt

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

Start Hunting!