Facebook
From ja, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 130
  1. import Bank._
  2.   import Ordering.Double.TotalOrdering
  3.   val poczatkowa = 250d
  4.  
  5.   def oblicz(list:List[(String,Double)]):(Set[String],Double) = {
  6.    val wynik = list
  7.     .groupMapReduce(x => x._1)(x => x._2)(_+_) //Map[String,Double]
  8.     .toList
  9.     .sortBy(x => x._1)
  10.     .scanLeft(("",250d))((x,a) =>
  11.       (a._1,x._2+a._2)
  12.     )
  13.     .tail
  14.     .groupMap(x => x._2)(x => x._1)
  15.     .maxBy(_._1)
  16.    
  17.    (wynik._2.toSet,wynik._1)
  18.  
  19.   }
  20.  
  21.   println(oblicz(dane))
  22.