Last active
December 13, 2017 18:20
-
-
Save gorrotowi/67a272f0d39f3bed16005d1694b7dafc to your computer and use it in GitHub Desktop.
bplanet
This file contains 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 java.io.File | |
import java.io.InputStream | |
import kotlin.math.sqrt | |
fun main(args: Array<String>) { | |
val inputStream: InputStream = File("src/test_case.txt").inputStream() | |
val lineList = mutableListOf<String>() | |
inputStream.bufferedReader().useLines { lines -> | |
lines.forEach { | |
lineList.add(it) | |
} | |
} | |
val numTest = lineList[0].toInt() | |
val numTestCases = lineList[1].toInt() | |
val listCoord = (0 until numTestCases).map { | |
lineList[it + 2].split(regex = "\\s".toRegex()) | |
} | |
var numArchi = 0 | |
val archipielagosNum = (0 until listCoord.size).map { i -> | |
val point1 = arrayOf(listCoord[i][0].toInt(), listCoord[i][1].toInt()) | |
(i + 1 until listCoord.size).map { j -> | |
if (j <= listCoord.size) { | |
val point2 = arrayOf(listCoord[j][0].toInt(), listCoord[j][1].toInt()) | |
(j + 1 until listCoord.size).map { k -> | |
if (k <= listCoord.size) { | |
println("$i - $j - $k") | |
val point3 = arrayOf(listCoord[k][0].toInt(), listCoord[k][1].toInt()) | |
println("points---->${point1[0]},${point1[1]} - ${point2[0]},${point2[1]} - ${point3[0]},${point3[1]}") | |
println(isArchipielago(point1, point2, point3)) | |
if (isArchipielago(point1, point2, point3)) { | |
numArchi += 1 | |
} | |
} | |
} | |
} | |
} | |
} | |
// val archipielagosNum = (0 until listCoord.size).map { | |
// if ((it + 1) < listCoord.size && (it + 2) < listCoord.size) { | |
// val point1 = arrayOf(listCoord[it][0].toInt(), listCoord[it][1].toInt()) | |
// val point2 = arrayOf(listCoord[it + 1][0].toInt(), listCoord[it + 1][1].toInt()) | |
// val point3 = arrayOf(listCoord[it + 2][0].toInt(), listCoord[it + 2][1].toInt()) | |
// println(isArchipielago(point1, point2, point3)) | |
// if (isArchipielago(point1, point2, point3)) { | |
// numArchi += 1 | |
// } | |
// } | |
// } | |
println("----->>> $numArchi") | |
println("----->>> ${archipielagosNum.size}") | |
} | |
//fun isArchipielago(p1: Array<Int>, p2: Array<Int>, p3: Array<Int>): Boolean { | |
// val dist1 = (p2[0] - p1[0]) * (p2[0] - p1[0]) | |
// val dist2 = (p3[0] - p1[0]) * (p3[0] - p1[0]) | |
//// val dist3 = (p3[0] - p1[0]) * (p3[0] - p1[0]) | |
// println("distancia ->>>> $dist1 - $dist2") | |
// return when (dist1) { | |
// dist2 -> true | |
// else -> false | |
// } | |
//} | |
fun isArchipielago(p1: Array<Int>, p2: Array<Int>, p3: Array<Int>): Boolean { | |
val dist1 = sqrt(Math.pow((p2[0] - p1[0]).toDouble(), 2.0) + Math.pow((p2[1] - p1[1]).toDouble(), 2.0)) | |
val dist2 = sqrt(Math.pow((p3[0] - p1[0]).toDouble(), 2.0) + Math.pow((p3[1] - p1[1]).toDouble(), 2.0)) | |
println("$dist1 - $dist2") | |
return when (dist1) { | |
dist2 -> true | |
else -> false | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment