Skip to content

Instantly share code, notes, and snippets.

@testfirstcoder
Last active November 17, 2015 13:01
Show Gist options
  • Save testfirstcoder/ed67d8b850c6512e0b7d to your computer and use it in GitHub Desktop.
Save testfirstcoder/ed67d8b850c6512e0b7d to your computer and use it in GitHub Desktop.
ProjectEuler in Scala
1 to 1000 - 1 filter(x => x % 3 == 0 || x % 5 == 0) sum
val fibonacci: Stream[Int] = 1 #:: fibonacci.scanLeft(2)(_+_)
fibonacci filter (_ % 2 == 0) takeWhile(_ < 4000000) sum
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
(1 to 1000).map(x => BigInt(x).pow(x)).sum % BigInt(10).pow(10)
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