Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package o1
- import scala.math._
- package object rainfall {
- // What goes here is described in Chapter 6.4.
- def averageRainfall( wek: Vector[Int] ) = {
- var pom = wek.takeWhile( _ < 999999)
- pom = pom.filter(_ >=0)
- var suma = pom.sum
- if(pom.length>0){
- var wyn = suma/pom.length
- Some(wyn)
- }
- else None
- }
- def drySpell( wek: Vector[Int] , length: Int ) = {
- var pom1 = wek.sliding(length).toVector
- var result = 10000000
- for ( i <- 0 to pom1.length-1)
- {
- if( pom1(i).exists( _<0) == false && pom1(i).exists(_ > 5)==false && pom1.exists( _ == 999999)==false) result = min(result, i)
- }
- if(result == 10000000) result= -1
- result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement