Cody

Problem 2635. Higher! Lower!

Solution 2990692

Submitted on 25 Sep 2020 by Alex
  • Size: 57
  • 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
hi_bound=1024; lo_bound=1; right_answer=512; assert(isequal(high_or_low(lo_bound,hi_bound,right_answer), 512))

guess = 512

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

guess = 512 guess = 768 guess = 640 guess = 576 guess = 544 guess = 528 guess = 520 guess = 516 guess = 514 guess = 513

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

guess = -8 guess = -4 guess = -2 guess = -3

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

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

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

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

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

guess = 32767 guess = 16383 guess = 8191 guess = 4095 guess = 2047 guess = 1023 guess = 1535 guess = 1279 guess = 1151 guess = 1087 guess = 1055 guess = 1039 guess = 1031 guess = 1027 guess = 1025 guess = 1024

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

guess = 0 guess = 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!