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
package zerosum.project.euler; | |
public class Euler0001 { | |
// public int filter(int number) { | |
// return (number % 3 == 0 || number % 5 == 0) ? number : 0; | |
// } | |
public int execute(int number) { | |
int sum = 0; |
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
object Euler0002 { | |
def main(args: Array[String]): Unit = | |
println(fibo_rec(1,2,4000000).filter(_%2==0).sum) | |
def fibo_rec(x: Int, y: Int, max: Int): List[Int] = | |
if (y > max) Nil else y :: fibo_rec(y, x+y, max) | |
} |
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
object Euler0003 { | |
def main(args: Array[String]): Unit = { | |
println(largiest_prime_factor(600851475143L)) | |
} | |
private def largiest_prime_factor(n: Long) = { | |
sieve((2 to Math.sqrt(n).toInt).toList).filter(n%_==0).max | |
} |
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
object Euler0004 { | |
def main(args: Array[String]): Unit = { | |
println(findLargiestPalindrome(3)) | |
} | |
private def findLargiestPalindrome(digit: Int): Int = { | |
val minRange = Math.pow(10, digit-1).toInt | |
val maxRange = Math.pow(10, digit).toInt | |
val factors = (minRange until maxRange).toList |
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
object Euler0005 { | |
def main(args: Array[String]): Unit = { | |
val factors = (1 to 20).toList | |
println(getSmallestMultiple(factors)) | |
} | |
private def getSmallestMultiple(factors: List[Int]): Int = { | |
getSmallestMultiple(factors, Nil).product |
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
object Euler0006 { | |
def main(args: Array[String]): Unit = { | |
val range = (1 to 100).toList | |
println(differenceOfSumSquare(range)) | |
} | |
private def differenceOfSumSquare(range: List[Int]): Int = { | |
val sumOfSquare = range.map(Math.pow(_, 2)).sum.toInt | |
val squareOfSum = Math.pow(range.sum, 2).toInt |
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
object Eulre0008 { | |
private val num = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760605886116467109405077541002256983155200055935729725716362695618826704282524836008232 |
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
object Euler0009 { | |
private val max = 1000 | |
def main(args: Array[String]): Unit = { | |
println( | |
buildTriplets(1, 2, Nil).filter(_.isPitagolyan).map(_.product) | |
) | |
} |
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
/* | |
* $ scalac -cp . euler.scala Euler0010.scala | |
* $ scala Euler0010 <arg: Int> | |
*/ | |
import euler.zerosum.Sieve._ | |
import euler.zerosum.Time._ | |
object Euler0010 { | |
private def execute(max: Long): Long = { |
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
package euler.zerosum | |
object Euler0013 { | |
def main(args: Array[String]) { | |
println( | |
numbers.map(_.sliding(10, 10).map(_.toDouble).toList) | |
.foldRight(List.fill(10)((0D, 0D)))(_ zip _.map(sumOfTuple(_))) | |
.map(sumOfTuple(_)) | |
.reduceRight(_ + _ * Math.pow(10, -10)) |
OlderNewer