Last active
November 17, 2015 13:01
-
-
Save testfirstcoder/ed67d8b850c6512e0b7d to your computer and use it in GitHub Desktop.
ProjectEuler in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 to 1000 - 1 filter(x => x % 3 == 0 || x % 5 == 0) sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val fibonacci: Stream[Int] = 1 #:: fibonacci.scanLeft(2)(_+_) | |
fibonacci filter (_ % 2 == 0) takeWhile(_ < 4000000) sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val numbers = 1 to 10000 | |
val properDivisorsSum = numbers.map(e => (e, numbers slice(0, e/2) filter(e % _ == 0) sum)) | |
properDivisorsSum | |
.filter{case(a,b) => properDivisorsSum exists{case(c,d) => a != b && a == d && b == c}} | |
.map(_._1) | |
.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1 to 1000).map(x => BigInt(x).pow(x)).sum % BigInt(10).pow(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val range = 1 to 100 | |
Math.pow(range.sum, 2).toInt - range.map(x => x * x).sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment