正整数のゲーデル数化?
Posted feedbacks - VB.net
素数導出コードを書く気が起こりません。 無限精度整数がないのでやな感じです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | Module Module1
Sub Main()
Console.WriteLine(Goedel(9))
Console.WriteLine(Goedel(81))
Console.WriteLine(Goedel(230))
End Sub
Public Function Goedel(ByVal n As Integer) As Double
If n < 0 Then Throw New ArgumentOutOfRangeException()
Dim digits As New List(Of Integer)
Dim primes As Integer()
Dim r As Double
While (n > 0)
digits.Add(n Mod 10)
n = n \ 10
End While
primes = GetPrimes(digits.Count)
r = 1
For i As Integer = 0 To digits.Count - 1
r *= primes(i) ^ digits(digits.Count - i - 1)
Next
Return r
End Function
Public Function GetPrimes(ByVal count As Integer) As Integer()
If count > 10 Then Throw New ArgumentOutOfRangeException()
Dim r(count - 1) As Integer
Array.Copy(PrimeSeeds, 0, r, 0, count)
Return r
End Function
Private PrimeSeeds As Integer() = New Integer() {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
End Module
|

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