// problem 1 var one = (3 until 1000 by 3 sum) + (5 until 1000 by 5 sum) - (15 until 1000 by 15 sum) // or better yet var two = (3 until 1000 filter (x => x % 3 == 0 || x % 5 == 0) sum)
Problem 2
val limit = 4000000 val fibs: Stream[Int] = 1 #:: fibs.scanLeft(1)(_ + _) val result = fibs takeWhile(_ <= limit) filter(_ % 2 == 0) sum
Problem 4
var maxPalindrom = (for ( i <- (100 until 999 reverse); j <- (100 until 999 reverse) if (i * j).toString() == (i * j).toString().reverse ) yield (i * j)) max
Problem 5
val l = 20 val d = 2 to l var result = l while(d.takeWhile(result % _ == 0).length != d.length) { result += l } println(result)
Problem 6
val sosq = 1 to limit map(x => x * x) sum val temp = 1 to limit sum val sqos = temp * temp val result = sqos - sosq println(result)
Maybe next time I should start with problem 377 and work my way down...
No comments:
Post a Comment