Browse Source

Read the test file

Toni Fadjukoff 8 years ago
parent
commit
40f2334d01
2 changed files with 41 additions and 4 deletions
  1. 7 0
      build.gradle
  2. 34 4
      src/main/kotlin/name/lamperi/orbital/main.kt

+ 7 - 0
build.gradle View File

11
 }
11
 }
12
 apply plugin: 'idea'
12
 apply plugin: 'idea'
13
 apply plugin: 'kotlin'
13
 apply plugin: 'kotlin'
14
+
15
+repositories {
16
+    jcenter()
17
+}
18
+dependencies {
19
+    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
20
+}

+ 34 - 4
src/main/kotlin/name/lamperi/orbital/main.kt View File

2
 
2
 
3
 import java.io.File;
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
 data class Satellite (
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
 fun main(args : Array<String>) {
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
 }