Find the Words on the Grid! Write a program or function that extracts a word from a wordsearch using its start and end coordinates.

The Input

Your program or function should accept three parameters: the start coordinate, the end coordinate, and a wordsearch from which to extract the word.


The start coordinate can be taken in any format.


It will always be an integer
The bottom left of the grid is (0, 0)
You will not be provided with coordinates that go outside the bounds of the grid
You will not be provided with coordinates that are not vertical, horizontal, or perfectly diagonal to each other, such as (7, 0) and (0, 6).

The end coordinate will be taken in the same format as the start coordinate
The wordsearch will be a string, or your language's closest equivalent


It will be a grid of characters separated by a single space, with each row on a newline. It can have any height or width - which can be different - but it will always be a rectangle. For example:

A G O A T C A T
E A T M E N O W
W O R D S E A R
A K L L K J H G
N P L F G H F D
A S P L K J H G
O P I L F G H J
T F A S E J K L




J H P B L D J L T
F J L N F N P W H
W P R D T F J R Q
J L L L L J H H W
N P L F H H F D S
J T P L L J H H K
P P J L F H H J N
L F J T F J L L O




The Output

You should output a string, or your language's closest equivalent. As no wordsearches in real life ever ask to find a single letter, you may output nothing if the coordinates are the same.

Examples and Test Cases


First Grid Above:
(0, 4) and (4, 0) --> "APPLE"

(4, 0) and (0, 4) --> "ELPPA"

(1, 7) and (4, 7) --> "GOAT"

(0, 5) and (7, 5) --> "WORDSEAR"

(0, 6) and (5, 6) --> "EATMEN"

(0, 6) and (0, 7) --> "EA"

(7, 0) and (0, 7) --> "LHJGLRAA"

----------

Second Grid Above:
(1, 0) and (8, 7) --> "FJLHJJWT"


(1, 4) and (4, 4) --> "LLLL"

(1, 4) and (1, 4) --> "L" or ""
JavaScript (ES6) 108

(x,y,t,u,g)=&gt;eval(&quot;for(g=g.split`\n`.reverse(),r=g[y][2*x];x-t|y-u;)r+=g[y+=u&lt;y?-1:u&gt;y][2*(x+=t&lt;x?-1:t&gt;x)]&quot;)

Less golfed
(x,y,t,u,g)=&gt;{
    g=g.split`\n`.reverse();
    for(r = g[y][2*x]; x-t | y-u; )
        r+=g[y += u&lt;y ? -1 : u&gt;y][2*( x += t&lt;x ? -1 : t&gt;x)];
    return r
}