kenny + primzahlen

This commit is contained in:
2025-07-22 23:41:04 +02:00
parent 76caa8a218
commit 3edee3c19e
3 changed files with 153 additions and 177 deletions

View File

@@ -1,4 +1,6 @@
import math
from re import match # für unkennify
import streamlit as st
# ***recursive quersummenfunktion***
def q_sum(n):
@@ -20,6 +22,7 @@ def iq_sum(n):
# ***produziert eine Liste mit Primzahlen kleiner als grenze***
# ***nach dem Prinzip des "Sieb des Eratosthenes"***
@st.cache_resource
def primzahlliste(grenze):
primes = []
is_prime = [True] * grenze
@@ -36,6 +39,7 @@ def primzahlliste(grenze):
# ***alle permutationen generieren***
@st.cache_resource
def all_perms(liste):
if len(liste) <= 1:
yield liste
@@ -154,3 +158,24 @@ def rwig_to_coords(a, b, c):
+ (c % 100000 - c % 10000) / 100000000
+ (b % 100000 - b % 10000) / 1000000000)
return round(lat, 5), round(lon, 5)
def unkennify(text):
# Funktion hier entnommen und angepasst: https://www.namesuppressed.com/software/kenny.py
decoded = ''
codemap = str.maketrans('MmPpFf', '001122')
n_len = len(text)
i = 0
while i + 3 <= n_len:
if match('[MmPpFf]{3,}', text[i:i + 3]):
num = int(text[i:i + 3].translate(codemap), 3) # 'mpf' -> '012' -> 5
cypher = chr(num + ord('a')) # 5 -> 'f'
if text[i].isupper():
cypher = cypher.upper()
decoded = decoded + cypher
i = i + 3
else:
decoded = decoded + text[i]
i = i + 1
if i < n_len:
decoded = decoded + text[i:]
return decoded