<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-6374583985636407395.post5747269780235173..comments</id><updated>2011-06-10T03:37:05.755-07:00</updated><category term='user_group'/><category term='scala'/><category term='PL research'/><category term='scala-blogs.org'/><category term='actors'/><category term='tutorial'/><category term='monad'/><category term='teaser'/><category term='community'/><category term='XML'/><category term='parsing'/><category term='new release'/><category term='reified types'/><category term='meta-programming'/><category term='pdx'/><category term='lift'/><category term='links'/><category term='sample'/><category term='mapreduce'/><category term='hadoop'/><category term='scala static dynamic'/><category term='comet'/><category term='user group'/><category term='osgi'/><category term='manifests'/><category term='smr'/><category term='combinators'/><category term='brisbane'/><category term='official'/><category term='type erasure'/><category term='twitter'/><category term='portland'/><category term='typechecking'/><category term='project euler'/><category term='class'/><category term='gdata'/><category term='variable binding'/><category term='october'/><category term='release'/><category term='sxr'/><category term='boston'/><category term='melbourne'/><category term='tool:maven'/><title type='text'>Comments on Scala Blog: Fun with Project Euler and Scala</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.scala-blogs.org/feeds/5747269780235173/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html'/><author><name>Steve Jenson</name><uri>http://www.blogger.com/profile/09686593839106107926</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://2.bp.blogspot.com/-z-C5VW1Iqcc/TssXb0xNUWI/AAAAAAAAAYU/9HTuwKzKAGo/s220/stevej_ded_profile-1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-1536969367484382871</id><published>2011-06-10T03:37:05.755-07:00</published><updated>2011-06-10T03:37:05.755-07:00</updated><title type='text'>For problem 5, an efficient algorithm using Euler&amp;...</title><content type='html'>For problem 5, an efficient algorithm using Euler&amp;#39;s method to find GCD:&lt;br /&gt;&lt;br /&gt;def gcd(a:Long,b:Long):Long={&lt;br /&gt;val r=a%b&lt;br /&gt;if(r==0)b else gcd(b,r)&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;(1l to 20l) reduce {(a,v)=&amp;gt;a*v/gcd(a,v)}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1536969367484382871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1536969367484382871'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1307702225755#c1536969367484382871' title=''/><author><name>scand1sk</name><uri>http://www.blogger.com/profile/15042980858120633568</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1834841427'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-1646025754937609679</id><published>2011-06-04T10:29:26.279-07:00</published><updated>2011-06-04T10:29:26.279-07:00</updated><title type='text'></title><content type='html'>This comment has been removed by the author.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1646025754937609679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1646025754937609679'/><author><name>Jason</name><uri>http://www.blogger.com/profile/08210925620486467080</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://2.bp.blogspot.com/-HBsTeOyLkNQ/TemHc9kPXWI/AAAAAAAAAAg/C_pWWsResRE/s220/225747_554156419147_21600303_31712183_1680797_n.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.contentRemoved' value='true'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-654352399'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-1807364046667695729</id><published>2011-01-22T10:35:32.238-08:00</published><updated>2011-01-22T10:35:32.238-08:00</updated><title type='text'>Hello,

We are delighted to inform you that Codefe...</title><content type='html'>Hello,&lt;br /&gt;&lt;br /&gt;We are delighted to inform you that Codefest&amp;#39;11, the annual International online coding festival of Computer Engineering Society, IT-BHU, has been unveiled. CodeFest is a unique fest wherein concepts of mathematics, logic, artificial intelligence, algorithms, language syntax, etc. are required to be deployed in programming; these concepts manifest themselves in solving problems effectively and efficiently!&lt;br /&gt;&lt;br /&gt;CodeFest was started last year. CodeFest&amp;#39;10 was a phenomenal success with participation from all over the globe. CodeFest&amp;#39;11 is geared up with some new and pepped up events, while maintaining the integrity of its standards.This year CodeFest has associated with Technex&amp;#39;11, the annual all India Technical Festival of IT-BHU, to expand its horizons.&lt;br /&gt;&lt;br /&gt;Here is a brief description of the constituent online events:&lt;br /&gt;&lt;br /&gt;    * Mathmania: A mathematical puzzle contest that puts mathematical and computational skills to test.&lt;br /&gt;    * Manthan: An algorithm intensive programming contest that would require coders to tailor existing standard algorithms.&lt;br /&gt;    * Perplexed: A programming contest, aimed to test the knowledge of C, wherein codes will be rewarded against syntactic constraints.&lt;br /&gt;    * Ratespiel: A technical contest covering different areas of Computer Science.&lt;br /&gt;    * Virtual Combat: An educational game wherein teams of programmed robotic tanks will fight the battles for glory. Codes Do Fight! Watch this out.&lt;br /&gt;&lt;br /&gt;Visit our website for more details.&lt;br /&gt;&lt;br /&gt;Few exciting statistics about Codefest&amp;#39;10:&lt;br /&gt;&lt;br /&gt;    * 2354 registrations (including 128 professionals) from 680 different institutions, across 59 countries&lt;br /&gt;    * Some participants were among the winners of Google Code Jam, Top Coder SRMs and ACM ICPC&lt;br /&gt;    * Total prize money was a whopping amount of 260,000 INR!&lt;br /&gt;    * Codefest &amp;#39;10 was the largest online coding festival of the Indian subcontinent in 2010 in terms of prize money!&lt;br /&gt;    * Codefest&amp;#39;10 was the second largest online coding festival of the Indian subcontinent in 2010, next to Bitwise&lt;br /&gt;    * Gained recognition from several international organizations including Codechef, Adobe, British Telecom, TCS and IEEE&lt;br /&gt;&lt;br /&gt;The Codefest&amp;#39;11 team has set out to unleash a yet another coding extravaganza. We hope that your participation would raise the level of competition in Codefest&amp;#39;11. Feel free to contact us at codefest@itbhu.ac.in or reach us personally at:&lt;br /&gt;&lt;br /&gt;    * Mohit Bansal mohit.bansal.cse06@itbhu.ac.in&lt;br /&gt;    * Saket Saurabh saket.saurabh.cse07@itbhu.ac.in&lt;br /&gt;&lt;br /&gt;We wish you all the best for Codefest&amp;#39;11 and for your future endeavours.&lt;br /&gt;&lt;br /&gt;Happy coding, and be free!&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Team Codefest&lt;br /&gt;Visit us at http://itbhu.ac.in/codefest&lt;br /&gt;Mail us at codefest@itbhu.ac.in&lt;br /&gt;Check out our page at http://facebook.com/codefest&lt;br /&gt;Follow us at http://twitter.com/c0defest/&lt;br /&gt;Read our blog at http://itbhu.ac.in/codefest/blog&lt;br /&gt;&lt;br /&gt;Do Watch The Virtual Combat Promotional Video:&lt;br /&gt;http://www.youtube.com/watch?v=v1rY3tyTj50</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1807364046667695729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1807364046667695729'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1295721332238#c1807364046667695729' title=''/><author><name>inderjeet</name><uri>http://www.blogger.com/profile/16471023721415431609</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-558241397'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-3163990029632974391</id><published>2010-12-26T07:59:11.871-08:00</published><updated>2010-12-26T07:59:11.871-08:00</updated><title type='text'>Awesome post, although I still prefer to use C#</title><content type='html'>Awesome post, although I still prefer to use C#</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3163990029632974391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3163990029632974391'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1293379151871#c3163990029632974391' title=''/><author><name>ssmm987</name><uri>http://www.blogger.com/profile/06690123743954592845</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-292041161'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-7952168033018050666</id><published>2008-10-17T07:37:00.000-07:00</published><updated>2008-10-17T07:37:00.000-07:00</updated><title type='text'>I had fun with my solution to problem 6.  By using...</title><content type='html'>I had fun with my solution to problem 6.  By using implicits I made sum and square functions that work with either lists of numbers or single numbers, so they can be applied in either order:&lt;BR/&gt;&lt;BR/&gt;implicit def int2list(i: Int) = List(i)&lt;BR/&gt;implicit def list2int(l: List[Int]) = l(0)&lt;BR/&gt;&lt;BR/&gt;def sum(xs: List[Int]) = xs.foldLeft(0)(_+_)&lt;BR/&gt;def square(xs: List[Int]) = xs.map(x =&amp;gt; x*x)&lt;BR/&gt;&lt;BR/&gt;val xs = (1 to 100).toList&lt;BR/&gt;println((sum(square(xs)) - square(sum(xs))).abs)</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7952168033018050666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7952168033018050666'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1224254220000#c7952168033018050666' title=''/><author><name>David</name><uri>http://www.blogger.com/profile/17923571645335186078</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1277002613'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-7627126248201278574</id><published>2008-10-01T12:54:00.000-07:00</published><updated>2008-10-01T12:54:00.000-07:00</updated><title type='text'>Here&amp;#39;s my solution to problem 5.  I don&amp;#39;t ...</title><content type='html'>Here&amp;#39;s my solution to problem 5.  I don&amp;#39;t know if it gives correct results for all numbers, but it appears to work until the result exceeds the capacity of Int.&lt;BR/&gt;&lt;BR/&gt;(1 to 20).foldLeft(1){ (product,n) =&amp;gt;&lt;BR/&gt;  val r_raw = product % n&lt;BR/&gt;  val r = if (r_raw == 0) n else r_raw&lt;BR/&gt;  product * (if (n % r == 0) (n / r) else n)&lt;BR/&gt;}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7627126248201278574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7627126248201278574'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1222890840000#c7627126248201278574' title=''/><author><name>Matt</name><uri>http://oldfashionedsoftware.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2022002890'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-3194790421835914246</id><published>2008-06-19T01:16:00.000-07:00</published><updated>2008-06-19T01:16:00.000-07:00</updated><title type='text'>My solution to Problem 7:&lt;br&gt;    var ps:Stream[Int...</title><content type='html'>My solution to Problem 7:&lt;BR/&gt;    var ps:Stream[Int] = Stream.cons(2,&lt;BR/&gt;    　　　　　　　　　　　　Stream.from(3).filter{ n =&gt;&lt;BR/&gt;    　　　　　　　　　　　　　　ps.takeWhile(p =&gt; p*p &lt;= n).forall(n%_ !=0)&lt;BR/&gt;    　　　　　　　　　　　})&lt;BR/&gt;    ps(10000)&lt;BR/&gt;And there has some codes for Project Euler:&lt;BR/&gt;http://eastsun.javaeye.com/category/34059</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3194790421835914246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3194790421835914246'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1213863360000#c3194790421835914246' title=''/><author><name>Eastsun</name><uri>http://www.blogger.com/profile/03765648865223091436</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1313956440'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-7849396009994896059</id><published>2008-06-19T01:11:00.000-07:00</published><updated>2008-06-19T01:11:00.000-07:00</updated><title type='text'></title><content type='html'>This comment has been removed by the author.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7849396009994896059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7849396009994896059'/><author><name>Eastsun</name><uri>http://www.blogger.com/profile/03765648865223091436</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.contentRemoved' value='true'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1313956440'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-4094351449248982951</id><published>2008-04-23T19:42:00.000-07:00</published><updated>2008-04-23T19:42:00.000-07:00</updated><title type='text'>Ugh that looks horrible. See the formatted code he...</title><content type='html'>Ugh that looks horrible. See the formatted code here:&lt;BR/&gt;http://codepad.org/5RvHTTXB</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/4094351449248982951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/4094351449248982951'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1209004920000#c4094351449248982951' title=''/><author><name>Garrett Rowe</name><uri>http://www.blogger.com/profile/06362501128519741915</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-527936723'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-4843512495569430506</id><published>2008-04-23T19:19:00.000-07:00</published><updated>2008-04-23T19:19:00.000-07:00</updated><title type='text'>I know I'm a little late to the conversation. But ...</title><content type='html'>I know I'm a little late to the conversation. But I just wanted to present another take on the Sieve of Eratosthenes. Really its just a Scala translation of the Haskell algorithm posted here: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf&lt;BR/&gt;&lt;BR/&gt;Caveat: I'm a Scala noob so this may not be idiomic Scala.&lt;BR/&gt;&lt;BR/&gt;   /**&lt;BR/&gt;    * Returns an infinite stream of prime numbers.&lt;BR/&gt;    * The algortihm is ported from the Haskell algorithm discussed in&lt;BR/&gt;    * the "Genuine Sieve of Eratosthenes" by Melissa E. O'Neill&lt;BR/&gt;    * fond here: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf&lt;BR/&gt;    */&lt;BR/&gt;   def primes : Stream[Int] = &lt;BR/&gt;   {&lt;BR/&gt;      def sieve(nums : Stream[Int], table : Map[Int, List[Int]])&lt;BR/&gt;            : Stream[Int] =&lt;BR/&gt;      {        &lt;BR/&gt;         val curr = nums.head&lt;BR/&gt;         table.get(curr) match&lt;BR/&gt;         { &lt;BR/&gt;            case None    =&gt; Stream.cons(curr&lt;BR/&gt;                               , sieve(nums.tail&lt;BR/&gt;                               , table.update(curr * curr, List(curr)))) &lt;BR/&gt;            case Some(v) =&gt; sieve(nums.tail&lt;BR/&gt;                               , v.foldLeft (table - curr)(reinsert (curr) _ ))&lt;BR/&gt;         }&lt;BR/&gt;      }&lt;BR/&gt;      &lt;BR/&gt;      def reinsert(curr : Int) (table : Map[Int, List[Int]], prime : Int)&lt;BR/&gt;             : Map[Int, List[Int]] =&lt;BR/&gt;      {&lt;BR/&gt;         val newVal = prime + curr&lt;BR/&gt;         table.get(newVal) match&lt;BR/&gt;         {&lt;BR/&gt;            case None =&gt; table.update(newVal, List(prime))&lt;BR/&gt;            case Some(v) =&gt; table.update(newVal, prime::v)&lt;BR/&gt;         }&lt;BR/&gt;      }&lt;BR/&gt;      sieve(naturals tail, Map.empty)&lt;BR/&gt;   }</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/4843512495569430506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/4843512495569430506'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1209003540000#c4843512495569430506' title=''/><author><name>Garrett Rowe</name><uri>http://www.blogger.com/profile/06362501128519741915</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-527936723'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-1358515887466846492</id><published>2008-04-07T11:11:00.000-07:00</published><updated>2008-04-07T11:11:00.000-07:00</updated><title type='text'>Thanks for this post — I've enjoyed comparing my s...</title><content type='html'>Thanks for this post — I've enjoyed comparing my solutions to yours.&lt;BR/&gt;&lt;BR/&gt;I tried changing my solutions to use your implicit conversions, but hit the following problem getting my code to compile:&lt;BR/&gt;&lt;BR/&gt;https://lampsvn.epfl.ch/trac/scala/ticket/733&lt;BR/&gt;&lt;BR/&gt;As you can see, I thought it was a compiler bug, but Martin says the implicits ought be declared in such a way as to help the type inference a bit more. If I understand his suggestion correctly, it's better to write:&lt;BR/&gt;&lt;BR/&gt;implicit def pimpMyIterableInt(it: Iterable[Int]):RichIterableInt = new RichIterableInt(it)&lt;BR/&gt;class RichIterableInt(it: Iterable[Int]) {&lt;BR/&gt;    def sum = it.foldLeft(0)(_ + _)&lt;BR/&gt;}&lt;BR/&gt;&lt;BR/&gt;and in fact this made my compile problems go away.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1358515887466846492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/1358515887466846492'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1207591860000#c1358515887466846492' title=''/><author><name>Seth Tisue</name><uri>http://www.blogger.com/profile/18193878850743685199</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-867237420'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-3020977304343920246</id><published>2008-01-14T15:29:00.000-08:00</published><updated>2008-01-14T15:29:00.000-08:00</updated><title type='text'>You are right I was not looking good enough.</title><content type='html'>You are right I was not looking good enough.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3020977304343920246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3020977304343920246'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1200353340000#c3020977304343920246' title=''/><author><name>remco</name><uri>http://www.blogger.com/profile/03613525768175266371</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-245292553'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-8639879248710794546</id><published>2008-01-14T09:42:00.000-08:00</published><updated>2008-01-14T09:42:00.000-08:00</updated><title type='text'>evenly divisible is just divisible (i.e. producing...</title><content type='html'>evenly divisible is just divisible (i.e. producing no remainder when divided). Are you sure you checked the number properly? It is divisible by 9 -- if you look at the calculation, the number three appears twice in the multiplication list.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/8639879248710794546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/8639879248710794546'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1200332520000#c8639879248710794546' title=''/><author><name>Michel S.</name><uri>http://www.blogger.com/profile/07739882483773373075</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-667650614'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-4614815590816208920</id><published>2008-01-14T04:16:00.000-08:00</published><updated>2008-01-14T04:16:00.000-08:00</updated><title type='text'>is the answer of  Problem 5: What is the smallest ...</title><content type='html'>is the answer of  Problem 5: What is the smallest number that is evenly divisible by all of the numbers from 1 to 20&lt;BR/&gt;really the right answer?&lt;BR/&gt;9 is a number between 1 and 20 and your answer is not even divisible by 9. I am not sure what evenly divisible means.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/4614815590816208920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/4614815590816208920'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1200312960000#c4614815590816208920' title=''/><author><name>remco</name><uri>http://www.blogger.com/profile/03613525768175266371</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-245292553'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-3182990820756293111</id><published>2008-01-07T05:30:00.000-08:00</published><updated>2008-01-07T05:30:00.000-08:00</updated><title type='text'>Ah, thanks. I guess that's good enough for the pur...</title><content type='html'>Ah, thanks. I guess that's good enough for the purpose of answering the question.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3182990820756293111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3182990820756293111'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199712600000#c3182990820756293111' title=''/><author><name>Michel S.</name><uri>http://www.blogger.com/profile/07739882483773373075</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-667650614'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-2385480164713998375</id><published>2008-01-06T06:19:00.000-08:00</published><updated>2008-01-06T06:19:00.000-08:00</updated><title type='text'>Michel:&lt;br&gt;&lt;br&gt;I too found that the Sieve of Erato...</title><content type='html'>Michel:&lt;BR/&gt;&lt;BR/&gt;I too found that the Sieve of Eratosthenes lost its usefulness after a while. Thankfully, Java's math library has a BigInteger class with a "nextProbablePrime" method. Converting between Java's BigInteger and Scala's BigInt is a bit of a pain, but you can do the following:&lt;BR/&gt;&lt;BR/&gt;scala&gt; lazy val primes: Stream[BigInt] = Stream.cons(BigInt(2), primes.map(b =&gt; new BigInt(b.bigInteger.nextProbablePrime)))&lt;BR/&gt;primes: Stream[BigInt] = Stream(2, ?)&lt;BR/&gt;&lt;BR/&gt;scala&gt; primes drop 10000&lt;BR/&gt;res1: Stream[BigInt] = Stream(104743, ?)&lt;BR/&gt;&lt;BR/&gt;If you define some implicits than the definition for primes becomes a lot prettier.&lt;BR/&gt;&lt;BR/&gt;scala&gt; implicit def bigInt2BigInteger(b: BigInt) = b.bigInteger                                   &lt;BR/&gt;bigInt2BigInteger: (BigInt)java.math.BigInteger&lt;BR/&gt;&lt;BR/&gt;scala&gt; implicit def bigInteger2BigInt(b: java.math.BigInteger) = new BigInt(b)&lt;BR/&gt;bigInteger2BigInt: (java.math.BigInteger)BigInt&lt;BR/&gt;&lt;BR/&gt;scala&gt; lazy val primes: Stream[BigInt] = Stream.cons(2, primes.map(_.nextProbablePrime))&lt;BR/&gt;primes: Stream[BigInt] = Stream(2, ?)&lt;BR/&gt;&lt;BR/&gt;Hope this helps.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/2385480164713998375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/2385480164713998375'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199629140000#c2385480164713998375' title=''/><author><name>Jorge Ortiz</name><uri>http://www.blogger.com/profile/14454965475839432618</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-139858654'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-8848705379740957298</id><published>2008-01-06T03:32:00.000-08:00</published><updated>2008-01-06T03:32:00.000-08:00</updated><title type='text'>Great article! Haven't noticed Project Euler befor...</title><content type='html'>Great article! Haven't noticed Project Euler before, and now I'm hooked. Having used functional languages for several years, your post serves as a nice introduction to Scala-isms.. I've been finding the syntax a bit unnatural, and having concrete examples to compare my solutions to, makes the learning process easier.&lt;BR/&gt;&lt;BR/&gt;Any idea how to do problem 7 in Scala? In Haskell I can just use the Sieve of Eratosthenes and drop the first 10,000 prime numbers, but in Scala I ran out of heap space.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/8848705379740957298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/8848705379740957298'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199619120000#c8848705379740957298' title=''/><author><name>Michel S.</name><uri>http://www.blogger.com/profile/07739882483773373075</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-667650614'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-7472933043131951504</id><published>2007-12-31T11:29:00.000-08:00</published><updated>2007-12-31T11:29:00.000-08:00</updated><title type='text'>Actually even the takeWhile method is unnecessary....</title><content type='html'>Actually even the takeWhile method is unnecessary. &lt;BR/&gt;&lt;BR/&gt;   def largestPrimeFactor(n: Long): Long = {&lt;BR/&gt;    val p = Stream.from(2).&lt;BR/&gt;filter(n % _ == 0).head&lt;BR/&gt;    if (p == n) n&lt;BR/&gt;    else largestPrimeFactor(n / p)&lt;BR/&gt;  }&lt;BR/&gt;  &lt;BR/&gt;  println(largestPrimeFactor(317584931803L))</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7472933043131951504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/7472933043131951504'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199129340000#c7472933043131951504' title=''/><author><name>Oscar Picasso</name><uri>http://www.blogger.com/profile/14161739987239998942</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1689018768'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-9206206315919682153</id><published>2007-12-31T10:37:00.000-08:00</published><updated>2007-12-31T10:37:00.000-08:00</updated><title type='text'>For problem 3, this one is very fast (75 ms on my ...</title><content type='html'>For problem 3, this one is very fast (75 ms on my computer).&lt;BR/&gt;&lt;BR/&gt;I started with something more complicated and realized that it was very slow for big numbers. The interesting thing is that I discovered a much simpler solution while trying to optimize.&lt;BR/&gt;&lt;BR/&gt;  def largestPrimeFactor(n: Long): Long = {&lt;BR/&gt;    val p = Stream.from(2).&lt;BR/&gt;takeWhile(_ &lt;= n).&lt;BR/&gt;filter((x) =&gt; n % x == 0).&lt;BR/&gt;head&lt;BR/&gt;    if (p == n) n&lt;BR/&gt;    else largestPrimeFactor(n / p)&lt;BR/&gt;  }&lt;BR/&gt;  &lt;BR/&gt;  println(largestPrimeFactor(317584931803L))</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/9206206315919682153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/9206206315919682153'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199126220000#c9206206315919682153' title=''/><author><name>Oscar Picasso</name><uri>http://www.blogger.com/profile/14161739987239998942</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1689018768'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-5090467378195210890</id><published>2007-12-30T15:43:00.000-08:00</published><updated>2007-12-30T15:43:00.000-08:00</updated><title type='text'>Oscar:&lt;br&gt;&lt;br&gt;Thanks for catching the &amp;lt;= bug! I...</title><content type='html'>Oscar:&lt;BR/&gt;&lt;BR/&gt;Thanks for catching the &lt;= bug! I've fixed it in the post.&lt;BR/&gt;&lt;BR/&gt;And you're correct, Scala allows for both functional and imperative approaches. An even -more- imperative solution (no iterators, anonymous functions, filters, or folds) would be:&lt;BR/&gt;&lt;BR/&gt;var sum = 0&lt;BR/&gt;var curr = 1&lt;BR/&gt;var prev = 0&lt;BR/&gt;&lt;BR/&gt;while (curr &lt;= 1000000) {&lt;BR/&gt;  if (curr % 2 == 0)&lt;BR/&gt;    sum += curr&lt;BR/&gt;&lt;BR/&gt;  val next = curr + prev&lt;BR/&gt;  prev = curr&lt;BR/&gt;  curr = next&lt;BR/&gt;}&lt;BR/&gt;&lt;BR/&gt;Console.println(sum)</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/5090467378195210890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/5090467378195210890'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199058180000#c5090467378195210890' title=''/><author><name>Jorge Ortiz</name><uri>http://www.blogger.com/profile/14454965475839432618</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-139858654'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-6157067266395704585</id><published>2007-12-30T13:41:00.000-08:00</published><updated>2007-12-30T13:41:00.000-08:00</updated><title type='text'>A more imperative solution to problem 2 for a gent...</title><content type='html'>A more imperative solution to problem 2 for a gentle introduction to scala for java programmers ;) &lt;BR/&gt;&lt;BR/&gt;Your solution feels more idiomatic scala though. &lt;BR/&gt;&lt;BR/&gt;class FiboIter extends Iterator[Int] {&lt;BR/&gt;    var pp = 0&lt;BR/&gt;    var p = 1&lt;BR/&gt;    val hasNext = true&lt;BR/&gt;    def next = {&lt;BR/&gt;      val curr = pp + p&lt;BR/&gt;      pp = p&lt;BR/&gt;      p = curr&lt;BR/&gt;      curr&lt;BR/&gt;    }&lt;BR/&gt;  }&lt;BR/&gt;  println(new FiboIter().&lt;BR/&gt;    takeWhile(_ &lt;= 1000000).&lt;BR/&gt;      filter(_ % 2 == 0).&lt;BR/&gt;        foldLeft(0)(_ + _))&lt;BR/&gt;}&lt;BR/&gt;&lt;BR/&gt;By the way the problem stated "... which do not exceed one million...". So I think that the takeWhile function argument should take the &lt;= operator not &lt;. But in that case it didn't change the result.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/6157067266395704585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/6157067266395704585'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199050860000#c6157067266395704585' title=''/><author><name>Oscar Picasso</name><uri>http://www.blogger.com/profile/14161739987239998942</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1689018768'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-5818570037996729732</id><published>2007-12-30T09:44:00.000-08:00</published><updated>2007-12-30T09:44:00.000-08:00</updated><title type='text'>Jörn:&lt;br&gt;&lt;br&gt;I would use "to" instead of "until", ...</title><content type='html'>Jörn:&lt;BR/&gt;&lt;BR/&gt;I would use "to" instead of "until", since it's inclusive.&lt;BR/&gt;&lt;BR/&gt;Once again, pimping my Iterable[Int] with a "sum" method:&lt;BR/&gt;&lt;BR/&gt;implicit def iterableWithSum(it: Iterable[Int]) = new { def sum: BigInt = it.foldLeft(0)(_+_) }&lt;BR/&gt;&lt;BR/&gt;Except this time the result is coerced to be a BigInt, so I can take advantage of the "pow" method on BigInt.&lt;BR/&gt;&lt;BR/&gt;Then:&lt;BR/&gt;&lt;BR/&gt;(1 to 100).sum.pow(2) - (1 to 100).map(n =&gt; n*n).sum &lt;BR/&gt;&lt;BR/&gt;Daniel:&lt;BR/&gt;&lt;BR/&gt;Yes, that does use fewer instructions. The asymptotic complexity is unchanged though.&lt;BR/&gt;&lt;BR/&gt;Also:&lt;BR/&gt;&lt;BR/&gt;It has been brought to my attention that my original solution to Problem 3 was buggy, as it assumed that each prime factor only occurred once in the factorization. I've updated the blog post with a bug fix.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/5818570037996729732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/5818570037996729732'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1199036640000#c5818570037996729732' title=''/><author><name>Jorge Ortiz</name><uri>http://www.blogger.com/profile/14454965475839432618</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-139858654'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-448983718371366630</id><published>2007-12-29T11:40:00.000-08:00</published><updated>2007-12-29T11:40:00.000-08:00</updated><title type='text'>scala&amp;gt; (1 until 1000).foldLeft(0)((old, next) =...</title><content type='html'>scala&gt; (1 until 1000).foldLeft(0)((old, next) =&gt; old + (if (next % 3 == 0 || next % 5 == 0) next else 0))&lt;BR/&gt;res5: Int = 233168&lt;BR/&gt;&lt;BR/&gt;// Might run slightly faster as it only iterates through the array once</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/448983718371366630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/448983718371366630'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1198957200000#c448983718371366630' title=''/><author><name>Daniel Green</name><uri>http://www.blogger.com/profile/12330531444698401088</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-301886858'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-3097018227555202035</id><published>2007-12-29T10:48:00.000-08:00</published><updated>2007-12-29T10:48:00.000-08:00</updated><title type='text'>Great post and an interesting approach to learn Sc...</title><content type='html'>Great post and an interesting approach to learn Scala.&lt;BR/&gt;&lt;BR/&gt;My solution to problem 6 (What is the difference between the sum of the squares and the square of the sums?):&lt;BR/&gt;&lt;BR/&gt;  var sum = (1 until 101).foldLeft(0)(_ + _);&lt;BR/&gt;  var squareSum = sum * sum&lt;BR/&gt;  &lt;BR/&gt;  var sumSquare: Int = 0&lt;BR/&gt;  (1 until 101).foreach(n =&gt; sumSquare += n*n)&lt;BR/&gt;  println(squareSum - sumSquare)&lt;BR/&gt;&lt;BR/&gt;The output is correct, but I'm sure the solution could be improved a lot. I'm curious to see yours.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3097018227555202035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/3097018227555202035'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1198954080000#c3097018227555202035' title=''/><author><name>Jörn Zaefferer</name><uri>http://www.blogger.com/profile/11145041155115321548</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1093632576'/></entry><entry><id>tag:blogger.com,1999:blog-6374583985636407395.post-8235417784626655509</id><published>2007-12-28T17:51:00.000-08:00</published><updated>2007-12-28T17:51:00.000-08:00</updated><title type='text'>Fantastic Blog!</title><content type='html'>Fantastic Blog!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/8235417784626655509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6374583985636407395/5747269780235173/comments/default/8235417784626655509'/><link rel='alternate' type='text/html' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html?showComment=1198893060000#c8235417784626655509' title=''/><author><name>Daniel Green</name><uri>http://www.blogger.com/profile/12330531444698401088</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.scala-blogs.org/2007/12/project-euler-fun-in-scala.html' ref='tag:blogger.com,1999:blog-6374583985636407395.post-5747269780235173' source='http://www.blogger.com/feeds/6374583985636407395/posts/default/5747269780235173' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-301886858'/></entry></feed>
