Last active
August 29, 2015 13:56
-
-
Save eric-taix/0b748cec5cc226e422c9 to your computer and use it in GitHub Desktop.
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
import 'dart:io'; | |
import 'dart:math'; | |
double toRadian(degree) => PI * degree / 180; | |
double parseDouble(string) => double.parse(string.replaceAll(',','.')); | |
void main() { | |
List<double> userLocation = new List<double>.generate(2, (index) => PI * double.parse(stdin.readLineSync().replaceAll(',','.')) / 180); | |
List defibrillators = new List | |
.generate(int.parse(stdin.readLineSync()), (index) => stdin.readLineSync().split(';')) | |
..forEach((defibrillator) => defibrillator.add(distance(userLocation, defibrillator))); | |
defibrillators.sort((d1, d2) => d1[6].compareTo(d2[6])); | |
print(defibrillators[0][1]); | |
} | |
double distance(user, defibrillator) { | |
double longitude = toRadian(parseDouble(defibrillator[4])); | |
double latitude = toRadian(parseDouble(defibrillator[5])); | |
double x = (user[0] - longitude) * cos((user[1] + latitude) / 2); | |
double y = (user[1] - latitude); | |
return sqrt(x * x + y * y) * 6371; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment