Cody

Problem 46603. Higher! Lower! Correct!

Solution 2987281

Submitted on 24 Sep 2020 by Tim
  • Size: 52
  • 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
low = 1; high = 1024; target = 512; guesses = 512; assert(isequal(high_or_low(low, high, target), guesses))

2   Pass
low = 1; high = 1024; target = 513; guesses = [512 768 640 576 544 528 520 516 514 513]; assert(isequal(high_or_low(low, high, target), guesses))

3   Pass
low = -16; high = 0; target = -3; guesses = [-8 -4 -2 -3]; assert(isequal(high_or_low(low, high, target), guesses))

4   Pass
low = 1; high = 1024; target = 1024; guesses = [512 768 896 960 992 1008 1016 1020 1022 1023 1024]; assert(isequal(high_or_low(low, high, target), guesses))

5   Pass
low = 0; high = 2048; target = 0; guesses = [1024 511 255 127 63 31 15 7 3 1 0]; assert(isequal(high_or_low(low, high, target), guesses))

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

7   Pass
low = 0; high = 1; target = 1; guesses = [0 1]; assert(isequal(high_or_low(low, high, target), guesses))

Suggested Problems

Community Treasure Hunt

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

Start Hunting!