Skip to content

Instantly share code, notes, and snippets.

@blacksheep557
Created January 8, 2020 05:44
Show Gist options
  • Select an option

  • Save blacksheep557/f8b31ebee4074974f1736354d4ef27f7 to your computer and use it in GitHub Desktop.

Select an option

Save blacksheep557/f8b31ebee4074974f1736354d4ef27f7 to your computer and use it in GitHub Desktop.
day 62
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