Given a line defined by (x1,y1) & (x2,y2),return the number of squares that the line crosses on the grid (a square is 1x1).
Coming next: return the number of squares for any geometrical shape
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers28
Suggested Problems
-
2817 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1305 Solvers
-
Find the largest value in the 3D matrix
1660 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
884 Solvers
-
Find the maximum two numbers of every column of a matrix
228 Solvers
More from this Author12
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Bug: The order of the arguments in the starting function definition is x1, x2, y1, y2, whereas the the order in the test cases is x1, y1, x2, y2.
Technically, this problem is actually requesting the number of unique intersections minus one. For instance in the first case of the test suite, the line crosses the point (5,3) which is shared by four squares, but we count only two, which is the expected behaviour when crossing an edge, but not a vertex: https://imgur.com/a/wCQ6SNG