From: Pavel Tcholakov <pchola...@gmail.com>
Date: Thu, 29 Sep 2011 07:01:19 +0200
Local: Thurs, Sep 29 2011 1:01 am
Subject: Re: The Project Euler Challenge - Exercise Your Scala Skills
Hey guys, new here! Good to have a local Scala forum at last!
As well as Project Euler, this is a great resource for learning Scala: http://aperiodic.net/phil/scala/s-99/ Adapted from the similar "99 Prolog problems" and "99 Lisp problems" P. On Wed, Sep 28, 2011 at 10:23 PM, Gary Pampara <gpamp...@gmail.com> wrote:
> No arguments at all. Learning is the most important thing :) > Euler problems are really, really entertaining - albeit that the later > For numeric types, such as Int in this case, the sum function is also > Eg (using the defined y value): y.sum == 233168 > Regards, > On Wed, Sep 28, 2011 at 9:47 PM, Mitch Wong Ho <oreomi...@gmail.com> wrote: >> Thank you Gary for your two solutions. If you run either of Gary's >> Just to finish off the solution and arrive at the answer, here is a >> y.foldLeft(0)((m: Int, n: Int) => m+n) //returns 233168 >> Checkout: http://oldfashionedsoftware.com/2009/07/10/scala-code-review-foldleft... >> Therefore this problem can be solved using Scala Collections. >> On Sep 28, 7:09 pm, Gary Pampara <gpamp...@gmail.com> wrote: >>> There are numerous ways to solve this first problem, but two that >>> 1. filter: >>> val x = (1 until 1000) filter { x => x % 3 == 0 || x % 5 == 0 } >>> 2. flatMap (using a for comprehension): >>> val y = for { i <- (1 until 1000) if (i %3 == 0 || i % 5 == 0) } yield i >>> Regards, >>> On Wed, Sep 28, 2011 at 3:56 PM, Mitch Wong Ho <oreomi...@gmail.com> wrote: >>> > #1 Add all the natural numbers below one thousand that are multiples You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||