The obstacle course
You are currently stuck in some kind of course and you have to escape. However, if you do not choose the fastest way then the exit will close in front of you. Your challenge is to find the fastest route in an obstacle course.
Input
Your input consists of a list with lists in it, a 2D grid containing only positive integers. For example, it might look as follows:
eg. [[0,1,2],[0,3,5],[2,6,1]]
which visually looks like:
0 1 2
0 3 5
2 6 1
Each number represents the time that is needed to pass the location. For example, (1,2)
takes 6 seconds to pass. Your code can take for granted that no conversions of the input have to be made to make it a list that works with your language.
Computing
Your starting position will also be (1,1)
, which in the input above is 2. You have to include those seconds in your final answer. From your starting position your goal is to work to (xmax, ymax)
, which in the input above is (3,3)
. You have to find the fastest route to get there, so the sum of your numbers must be minimal.
Note for example understanding: the grid is from 1 and on-wards, (0,0) is not the starting position. (1,1) is bottom left and (3,3) is top right in this example.
Output
Your code must output the minimal time it takes to reach the top right corner from the bottom left corner. In the input above this is 2 + 0 + 0 + 1 + 2 = 5
seconds. Your code should output nothing else than a whole integer.
Additional specifications
- Your may not move diagonally; only left, right, down, up
- This is code-golf, shortest code in bytes wins
- The grid wont always be square, but the start will always be connected to the end
- minimum input is a 1x1 grid
- grid will only contain positive integers
To sum up the given example:
Input: [[0,1,2],[0,3,5],[2,6,1]] // any format you like
Output: 5
How:
2 + 0 + 0 + 1 + 2 = 5