tag:blogger.com,1999:blog-3060516345583304229.post8142238891074770379..comments2023-06-04T06:50:29.767-07:00Comments on Ben Arciszewski Development: Project Euler Problem 2 in ScalaBen Arciszewskihttp://www.blogger.com/profile/02242641729372468998noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3060516345583304229.post-33211703989941963642012-01-09T07:33:31.635-08:002012-01-09T07:33:31.635-08:00HI renghen. I particularly like your use of the A...HI renghen. I particularly like your use of the API methods - head, sum, match, filter. I hope to become more familiar with the API as I work through the solutions.Ben Arciszewskihttps://www.blogger.com/profile/02242641729372468998noreply@blogger.comtag:blogger.com,1999:blog-3060516345583304229.post-29708922613556939062012-01-09T03:09:42.803-08:002012-01-09T03:09:42.803-08:00this is my version using list, because list are fu...this is my version using list, because list are fun<br /><br />object Euler2{<br /> <br /> def fibo(pList : List[Long]) : List[Long] = {<br /> pList match {<br /> case Nil => List(1)<br /> case 1::Nil => List(2,1)<br /> case a::b => pList.take(2).sum :: pList<br /> }<br /> }<br /> <br /> def main(args : Array[String]) : Unit = {<br /> <br /> var list : List[Long]= List(1)<br /> val limit = 4 * 1000 * 1000<br /> <br /> while(list.head < limit) {<br /> list = fibo(list)<br /> }<br /> <br /> list = list.tail<br /> val sum = list.filter(x => x%2 == 0).sum<br /> <br /> print("sum is " + sum)<br /> <br /> } <br /> <br />}renghenhttps://www.blogger.com/profile/00499465118272220585noreply@blogger.com