/*
List(
List(1,2,3,4),
List(5,6,7,8),
List(9,0)
)
↓
List(
List(1,5,9),
List(2,6,0),
List(3,7),
List(4,8)
)*/
case class Player(id: Int, name: String, score: Int)
val t: List[(Int, String, Int)] =
(1 to 17) zip ('a' to 'z') map (x => (x._1, x._2.toString, scala.util.Random.nextInt(100))) toList
val players = t.map(x => Player(x._1, x._2, x._3))
val sortedPlayers = players.sortBy(x => (- x.score, x.id))
def transpose[A](xs: List[List[A]]): List[List[A]] = xs.filter(_.nonEmpty) match {
case Nil => Nil
case ys: List[List[A]] => ys.map{ _.head }::transpose(ys.map{ _.tail })
}
transpose(sortedPlayers.grouped(4).toList)
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
11