Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2021-06-17T18:16:21+00:00 → 2021-06-21T10:16:33+00:00
| − | <language>FLACI_c3040gfy2wykcr</language> |
| − | <run id="60cb9175a56e0"> |
| − | M1| IF x2 = 0 THEN GOTO M2; |
| − | M3| x0 := x4 + 1; |
| − | M4| GOTO M1; |
| − | M2| x0 := x4 + 2 |
| + | <language>Python</language> |
| + | = Kreativaufgabe = |
| + | <code id="60cf2926d7b41"> |
| + | from itertools import product |
| + | |
| + | def h(w): |
| + | """Gödelisierung""" |
| + | sum = 0 |
| + | for index, ch in enumerate(w): |
| + | ko = 0 |
| + | if ch == "a": |
| + | ko = 1 |
| + | if ch == "b": |
| + | ko = 2 |
| + | sum += ko * 3 ** (len(w) - index - 1) |
| + | return sum |
| + | |
| + | def p_pred(goed): |
| + | """Prädikat testet, ob eine natürliche Zahl Gödelnummer ist""" |
| + | n = 0 |
| + | sum = 0 |
| + | while sum < goed: |
| + | for combination in product([1, 2], repeat = n): |
| + | sum = 0 |
| + | #combination = list(combination)[::-1] |
| + | #print("Combination", combination) |
| + | for index, coeff in enumerate(combination): |
| + | |
| + | sum += coeff * 3 ** index |
| + | #print(str(coeff) + " * 3 ** " + str(index)) |
| + | #print("Sum", sum, "=", goed, "?") |
| + | if sum == goed: |
| + | return list(combination)[::-1] |
| + | n += 1 |
| + | return [] |
| + | |
| + | def p(r, y): |
| + | if p_pred(y) and r <= y: |
| + | return 1 |
| + | return 0 |
| + | |
| + | def g(n): |
| + | """Folge der Gödelnummern""" |
| + | def f(p1, p2): |
| + | m = 0 |
| + | while True: |
| + | minus = 1 - p(p1, m) |
| + | if minus < 0: |
| + | minus = 0 |
| + | if minus == 0: |
| + | #print("return f", m) |
| + | return m |
| + | m += 1 |
| + | |
| + | if n == 1: |
| + | ret = f(0, n) |
| + | #print("return n==1", ret) |
| + | return ret |
| + | else: |
| + | res = f(g(n - 1) + 1, n) |
| + | #print("return else", res) |
| + | return res |
| + | |
| + | def k(n): |
| + | """k(n) = h^-1(g(n))""" |
| + | w = "" |
| + | coeffs = p_pred(n) |
| + | print(coeffs) |
| + | for coeff in coeffs: |
| + | ch = "" |
| + | if coeff == 1: |
| + | ch = "a" |
| + | if coeff == 2: |
| + | ch = "b" |
| + | w += ch |
| + | return w |
| + | |
| + | w = "a" |
| + | goedel_number = h(w) |
| + | </code> |
| + | |
| + | <run id="60cf2926d7bbc"> |
| + | #h(w): Goedelnummer zu w |
| + | #g(n): n-te Goedelnummer |
| + | #k(n): w zur n-ten Goedelnummer |
| + | |
| + | |
| + | w = "abb" |
| + | print("w", w) |
| + | goedel_number = h(w) |
| + | print("goedel_number", goedel_number) |
| + | print("g", g(goedel_number)) |
| + | print(k(goedel_number)) |
</run> | |
| + | |
| + | <run id="60cf295269eb2"> |
| + | for i in range(1, 11): |
| + | print(g(i)) |
| + | </run> |