Comment detail

正整数のゲーデル数化? (Nested Flatten)

やっぱり一度文字列化するの一番効率的で簡単みたいです。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import Data.Char

primes = sieve [2..] 
  where 
  sieve (x:xs) = x : sieve [y| y<-xs, y `mod` x /= 0]

goedel x = product $ zipWith (^) primes (map digitToInt (show x))

{-
*Main> goedel 9
512
*Main> goedel 81
768
*Main> goedel 230
108
-}

Index

Feed

Other

Link

Pathtraq

loading...