Skip to content

Instantly share code, notes, and snippets.

@daclouds
Created August 22, 2014 13:30
Show Gist options
  • Save daclouds/07b1fe3d2dcd4edea743 to your computer and use it in GitHub Desktop.
Save daclouds/07b1fe3d2dcd4edea743 to your computer and use it in GitHub Desktop.
object App extends App {
val testCaseNum = io.Source.fromFile("input.txt").getLines.toSeq.headOption.map(_.toLong)
// parse the range..
// val houses: Seq[(Long, Long)] = ???
// (0.0)
// (0,1)
// (1,1)
// (1,2)
// (2,2)
// (-1,2)
// (1,3)
// (0,0)
def getThePartyHouse(xList: Seq[Long], yList: Seq[Long]) = {
val xMedium = xList.sorted.apply(xList.size / 2)
val yMedium = yList.sorted.apply(yList.size / 2)
val houses: Seq[(Long, Long)] = for {
x <- xList
y <- yList
} yield (x, y)
val distances = houses.map { house =>
val xPoint = house._1
val yPoint = house._2
val distance = scala.math.abs((xPoint - xMedium) * (yPoint - yMedium))
println("X : %s, Y: %s, distance = %s".format(xPoint, yPoint, distance))
(distance, (xPoint, yPoint))
}
println(distances.minBy(_._1)._2)
}
val xs: Seq[Long] = Seq(-1, 1, 3)
val ys: Seq[Long] = Seq(2, 3, 0)
getThePartyHouse(xs, ys)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment