The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Message from discussion The Project Euler Challenge - Exercise Your Scala Skills

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Sep 29 2011, 1:01 am
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:

Adapted from the similar "99 Prolog problems" and "99 Lisp problems"
tutorials. Unlike project Euler, it tends to have less of an
algorithmic/mathematical "aha" focus and more aimed at teaching the
functional side of programming. Plus you can peek at the solutions

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
> ones can be extremely frustrating until that "aha" moment.

> For numeric types, such as Int in this case, the sum function is also
> available on the collections.

> Eg (using the defined y value): y.sum == 233168

> Regards,
> Gary

> On Wed, Sep 28, 2011 at 9:47 PM, Mitch Wong Ho <oreomi...@gmail.com> wrote:
>> In the name of fun and learning, I thought this would be a good way to
>> learn and apply Scala.

>> Thank you Gary for your two solutions.  If you run either of Gary's
>> statements in the interpreter, you get a List of values that multiples
>> of 3 or 5.

>> Just to finish off the solution and arrive at the answer, here is a
>> possible next-step after Gary's functions:

>> y.foldLeft(0)((m: Int, n: Int) => m+n) //returns 233168

>> Checkout: http://oldfashionedsoftware.com/2009/07/10/scala-code-review-foldleft...
>> for a good explanation on the foldLeft() function.

>> Therefore this problem can be solved using Scala Collections.

>> On Sep 28, 7:09 pm, Gary Pampara <gpamp...@gmail.com> wrote:
>>> Just remember that the solutions are supposed to be a secret :) It's
>>> an achievement to get them.

>>> There are numerous ways to solve this first problem, but two that
>>> quickly spring to mind are:

>>> 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,
>>> Gary

>>> 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
>>> > of 3 or 5.