Created
January 8, 2020 05:44
-
-
Save blacksheep557/f8b31ebee4074974f1736354d4ef27f7 to your computer and use it in GitHub Desktop.
day 62
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int maxCollinear(List<List<int>> points) { | |
| List<int> collinearPoins = []; | |
| for (int i = 0; i < points.length - 1; i++) { | |
| int counter = 0; | |
| for (int j = 0; j < points.length; j++) { | |
| if (j != i && j != (i + 1)) { | |
| if (arePointsCollinear(points[i], points[i + 1], points[j])) { | |
| counter++; | |
| } | |
| } | |
| } | |
| collinearPoins.add(counter); | |
| } | |
| print(collinearPoins); | |
| int maximum = collinearPoins.reduce(max) + 2; | |
| print(maximum); | |
| return maximum; | |
| } | |
| bool arePointsCollinear(List<int> first, List<int> second, List<int> third) { | |
| double slopeOne = (second[1] - first[1]) / (second[0] - first[0]); | |
| double slopeTwo = (third[1] - second[1]) / (third[0] - second[0]); | |
| return slopeOne.abs() == slopeTwo.abs(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment