Find the largest number n positions away from n
05AB1E, 21 bytes
vyN+Ny-})¹gL<Ãv¹yè})Z
Explanation
v } # for each num in input
yN+ # push index + num
Ny- # push index - num
) # wrap stack in a list
¹gL<Ã # remove indices outside the range of input
v¹yè}) # get list of elements in input at the remaining indices
Z # get max
Try it online!
Haskell, 61 57 55 bytes
f x=maximum[a|(n,a)<-x,(i,b)<-x,b==abs(n-i)]
f.zip[0..]
Usage example: (f.zip[0..]) [5,28,14,5,6,3,4,7]
-> 14
.
(More or less) a direct implementation of the definition: for each index n
of the input list x
keep a := x!!n
if there's an index i
where b := x!!i
equals abs(n-i)
. Find the maximum.
Edit: @xnor saved two bytes. Thanks!
Jelly, 10 bytes
,N+JFfJị¹Ṁ
Try it online! or verify all test cases.
How it works
,N+JFfJị¹Ṁ Main link. Argument: A (array)
,N Pair A with -A (element-wise negative).
J Yield the indices of A [1, ..., len(A)].
+ Add the elements of A (and their negatives) with the corr. indices.
F Flatten the resulting 2D array.
fJ Filter indices; remove invalid indices (not in [1, ..., len(A)]) from
the generated array. The result is the list of all indices of eligible
elements of A.
ị¹ Retrieve the corresponding elements of A.
Ṁ Take the maximum.