Skip to content

Instantly share code, notes, and snippets.

@hwiorn
Last active December 17, 2015 08:48
Show Gist options
  • Save hwiorn/5582328 to your computer and use it in GitHub Desktop.
Save hwiorn/5582328 to your computer and use it in GitHub Desktop.

Revisions

  1. hwiorn revised this gist May 21, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //20보다 작은 소수의 제곱끼리 모아서 곱셈
    //소수(<20)의 최대 제곱수(<20)를 모두 곱셈
    println((2 to 20).filter(BigInt(_).isProbablePrime(5)).
    map(k => (1 to 4).map(scala.math.pow(k, _)).
    map(k => (1 to 4).map(math.pow(k, _)).
    filter(_ <= 20).max).product.toInt)
  2. hwiorn revised this gist May 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //20보다 작은 소수의 제곱끼리 모아서 곱셈
    println((2 to 20).filter(BigInt(_).isProbablePrime(5)).
    map(k => (1 to 20).map(scala.math.pow(k, _)).
    map(k => (1 to 4).map(scala.math.pow(k, _)).
    filter(_ <= 20).max).product.toInt)
  3. hwiorn revised this gist May 15, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //20보다 작은 소수의 제곱끼리 모아서 곱셈
    println((2 to 20).filter(x => BigInt(x).isProbablePrime(1)).
    map(k => (1 to 20).map(y => scala.math.pow(k, y)).
    filter(n => n <= 20).max).product.toInt)
    println((2 to 20).filter(BigInt(_).isProbablePrime(5)).
    map(k => (1 to 20).map(scala.math.pow(k, _)).
    filter(_ <= 20).max).product.toInt)
  4. hwiorn revised this gist May 15, 2013. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,4 @@
    //20보다 작은 소수의 제곱끼리 모아서 곱셈
    //-#1
    println ((for(x <- 2 to 20; if((BigInt(x).isProbablePrime(1))))
    yield ((for(y <- 1 to 20; if(scala.math.pow(x, y) <= 20))
    yield scala.math.pow(x, y)).max)).product.toInt)

    //-#2
    println((2 to 20).filter(x => BigInt(x).isProbablePrime(1)).
    map(k => (1 to 20).map(y => scala.math.pow(k, y)).
    filter(n => n <= 20).max).product.toInt)
  5. hwiorn revised this gist May 15, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,10 @@
    //20보다 작은 소수의 제곱끼리 모아서 곱셈
    //-#1
    println ((for(x <- 2 to 20; if((BigInt(x).isProbablePrime(1))))
    yield ((for(y <- 1 to 20; if(scala.math.pow(x, y) <= 20))
    yield scala.math.pow(x, y)).max)).product.toInt)

    //-#2
    println((2 to 20).filter(x => BigInt(x).isProbablePrime(1)).
    map(k => (1 to 20).map(y => scala.math.pow(k, y)).
    filter(n => n <= 20).max).product.toInt)
  6. hwiorn revised this gist May 15, 2013. 1 changed file with 4 additions and 10 deletions.
    14 changes: 4 additions & 10 deletions euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,4 @@
    def z(x: Int, y: Int): Int = {
    if(x <= 1) y
    else if(x % y == 0) z(x / y, y)
    else z(x, y+1)
    }

    def l(a: Int) = (for(x <- 2 to a; if(z(x, 2)==x))
    yield ((for(y <- 1 to a; if(scala.math.pow(x, y) <= a))
    yield scala.math.pow(x, y)).max)).product.toInt
    println(l(20))
    //20보다 작은 소수의 제곱끼리 모아서 곱셈
    println ((for(x <- 2 to 20; if((BigInt(x).isProbablePrime(1))))
    yield ((for(y <- 1 to 20; if(scala.math.pow(x, y) <= 20))
    yield scala.math.pow(x, y)).max)).product.toInt)
  7. hwiorn created this gist May 15, 2013.
    10 changes: 10 additions & 0 deletions euler0005.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    def z(x: Int, y: Int): Int = {
    if(x <= 1) y
    else if(x % y == 0) z(x / y, y)
    else z(x, y+1)
    }

    def l(a: Int) = (for(x <- 2 to a; if(z(x, 2)==x))
    yield ((for(y <- 1 to a; if(scala.math.pow(x, y) <= a))
    yield scala.math.pow(x, y)).max)).product.toInt
    println(l(20))