Problem 56170. Dartboard Average I
A dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.
Given a vector v representing the arrangement of the values 1 to 20, and a target value t, return the average of t and the two values on either side of it in the vector v. Note that a dartboard is circular, so the values in v are assumed to wrap.
For example, a standard dartboard is represented by
v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];
If t = 6, your function should return mean([13 6 10]) = 9.6667.
If t = 20, it should return mean([5 20 1]) = 8.6667.
The vector v will always be a permutation of the values 1:20.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers152
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15527 Solvers
-
6659 Solvers
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
1819 Solvers
-
Number of 1s in the Binary Representation of a Number
444 Solvers
-
Find the minimum of the column-maximums of a matrix
442 Solvers
More from this Author22
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!