Scala for Java programmers, the Euler way - ep. 01 (2 of 3)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,611
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jan 6, 2011

This is for Java programmers who want to get a practical introduction to Scala. I assume basic knowledge about Scala, namely that it has some similarities to Java and produces standard JVM bytecode. In this series of tutorials, I will show you some Scala basics by walking you through a few Project Euler problems.

The first part is rather long and therefore split into three videos. I expect the next parts to be shorter.

Category:

Science & Technology

Tags:

License:

Standard YouTube License

  • likes, 0 dislikes

Link to this comment:

Share to:
see all

All Comments (3)

Sign In or Sign Up now to post a comment!
  • Sorry, dis-regard my note about val vs. var above. I can see now that you're revising your solution as you go.  :-)

  • Just a quick few notes: In Scala everything, including primitives, are proper objects, hence the need for Int vs int. Int is a valid object. The Scala compiler will convert it to a primitive int as necessary, but that's the main reason. Also, you might want to emphasis the use of val instead of var. This may change your solution somewhat, but it's still better practice and one that should be encouraged earlier on. Not sure if you've done this in your other vids yet, but it's worth noting.

  • Ok, a bit overkill to have an object and it is imperative and mutable, I just user the REPL.

    Make a function, use the function and sum the collection.

    def multiples(from: Int, to: Int) = for { x <- from until to if(x%3== 0 || x%5==0) } yield x

    val sum = multiples(1,1000).sum sum: Int = 233168

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more