正整数のゲーデル数化?
Posted feedbacks - Scala
1 2 3 4 5 6 7 8 9 10 11 | import java.lang.Double.parseDouble
def sieve(s: Stream[Int]): Stream[Int] =
Stream.cons(s.head, sieve(s.tail filter { _ % s.head != 0 }))
def primes = sieve(Stream.from(2))
def goedel(n:int) = {
var s = n.toString
primes.take(s.size).zipWithIndex.foldLeft(1d){(r, p) =>
r*Math.pow(p._1, parseDouble(s(p._2)+""))
}
}
|



nobsun
#4420()
Rating2/2=1.00
see: ゲーデル数
[ reply ]