Sam and Linda are taking a sleigh ride in a snowy forest. After taking a frolic in the fresh winter snow, they decide that they should head back. Unfortunately for Sam and Linda, the sun is starting to go down, and it is getting colder each minute.
Can you construct an algorithm that determines the minimum amount of time it will take Sam and Linda to get home?
Details and Assumptions:
For the purpose of this question, we can take the forest to be a 7 0 × 7 0 grid, with trees positioned at a collection of fixed coordinates (as stated below). Trees occupy the entire grid square in which they are positioned. Sam and Linda can travel one grid square directly North, South, West, or East of their current grid square (not diagonal) per minute. They cannot pass through trees, they are forced to go around them. Assume that Sam and Linda start off at the coordinate ( 6 5 , 4 ) and that they are trying to get to coordinate ( 7 , 6 2 ) . Also assume that the x - and y -coordinates both range from 1 to 7 0 .
This is the list of coordinates where trees are located.
This problem is part of The 12 Days of Math-Mas 2018
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Essentially, the program that I made uses a cellular automata that "spreads" across a 7 0 × 7 0 grid until it reaches the target coordinate, with each iteration of spread adding 1 minute to the timer. This is the code that I wrote to solve the problem (in Python):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Log in to reply
@Eli Lopez You can post your own solution to the problem, with this code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
It's just a standard BFS problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
Problem Loading...
Note Loading...
Set Loading...
My Python code is intended to provide a list of values indicating the minimum number of steps ( length of time) required to arrive at each cell in the entire forest. I stopped the code after the home destination was reached. For my own amusement and interest I am expanding the problem to print out a detailed set of directions to follow for one of the possible routes home. My intention is to have the code determine and print out a serial set of steps to make the trip. My output should look something like start,N,N,W,W,W,W,W,S,S ... S,S,home. I hope to develop the code to provided detailed directions for any trip that is possible from one location to another within a grid like the one provided.
By my calculations there are 997,920 possible unique (distinct in some way from any of the other) routes, each of which would take 144 minute, that Sam and Linda could have taken home. I did up a excel sheet showing the cells along the routes that Sam and Linda would have to travel to make the trip in 144 minutes. As It turned out on the Excel sheet the Y values from the table (north/South) are inverted ie larger values are lower.