DEV Community

Discussion on: Daily Challenge #121 - Who has the most money?

Collapse
 
logycon profile image
Igor

In Scala -

case class Student(name : String, fives: Int, tens: Int, twenties: Int) {
  override def toString = s"${name} -> ${worth}"
  def worth: Int = 5 * fives + 10 * tens + 20 * twenties
}

val students = List(
  Student("1", 5, 1, 4),
  Student("2", 5, 1, 4),
  Student("3", 5, 1, 4)
)

val winner = students.maxBy(f => f.worth) 
val winners = (winner :: students.filter(f => f.worth == winner.worth)).distinct

if (winners.size == students.size) 
  println("all")
else 
  println(winner)