|
@@ -2,14 +2,44 @@ package name.lamperi.orbital;
|
2
|
2
|
|
3
|
3
|
import java.io.File;
|
4
|
4
|
|
|
5
|
+// Latitude = South - North (-90...90)
|
|
6
|
+// Longitude = East West (-180...180)
|
|
7
|
+
|
|
8
|
+val EARTH_RADIUS = 6371.0; // KM
|
|
9
|
+
|
|
10
|
+data class Problem (
|
|
11
|
+ val seed : Double, val satellites : Set<Satellite>, val route : Route)
|
|
12
|
+
|
5
|
13
|
data class Satellite (
|
6
|
|
- val id : String, val lat : Double, val lon : Double, val height : Double)
|
|
14
|
+ val id : String, val lat : Double, val lon : Double, val height : Double)
|
7
|
15
|
|
8
|
16
|
|
9
|
|
-fun parseFile(file : java.io.File) {
|
10
|
|
- //val contents = file.readText()
|
|
17
|
+data class Route (
|
|
18
|
+ val startLat : Double, val startLon : Double, val endLat : Double, val endLon : Double)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+fun parseFile(file : java.io.File) : Problem {
|
|
22
|
+ val contents : String = file.readText()
|
|
23
|
+ var seed : Double = contents.splitToSequence('\n').first().splitToSequence(':').last().toDouble()
|
|
24
|
+ val satellites : Set<Satellite> = contents.splitToSequence('\n')
|
|
25
|
+ .filter { it.startsWith("SAT") }
|
|
26
|
+ .map {
|
|
27
|
+ val parts = it.split(',')
|
|
28
|
+ Satellite(id = parts[0], lat = parts[1].toDouble(),
|
|
29
|
+ lon = parts[2].toDouble(), height = parts[3].toDouble())
|
|
30
|
+ }.toSet()
|
|
31
|
+ var route : Route = contents.splitToSequence('\n')
|
|
32
|
+ .filter { it.startsWith("ROUTE") }
|
|
33
|
+ .map {
|
|
34
|
+ val parts = it.split(',')
|
|
35
|
+ Route(startLat = parts[1].toDouble(), startLon = parts[2].toDouble(),
|
|
36
|
+ endLat = parts[3].toDouble(), endLon = parts[4].toDouble())
|
|
37
|
+ }.first()
|
|
38
|
+ return Problem(seed = seed, satellites = satellites, route = route)
|
11
|
39
|
}
|
12
|
40
|
|
13
|
41
|
fun main(args : Array<String>) {
|
14
|
|
-
|
|
42
|
+ val file = File("src/main/resources/satellites.txt")
|
|
43
|
+ val problem = parseFile(file)
|
|
44
|
+ println(problem)
|
15
|
45
|
}
|