Organisation
This commit is contained in:
1 parent
936f13ca6d
commit
ff6266b2f8
14 files changed
+4614
No files matched your search
@@ -0,0 +1,61 @@
|
||||
## SymPy Merkhilfe
|
||||
|
||||
|**Kategorie**|**Funktion/Method**|**Beschreibung**|**Beispiel**|
|
||||
|---|---|---|---|
|
||||
|**Initialisierung**|`symbols()`|Definiert symbolische Variablen|`x, y = symbols('x y')`|
|
||||
||`Symbol()`|Erstellt ein einzelnes symbolisches Objekt|`a = Symbol('a')`|
|
||||
|**Gleichungen**|`solve()`|Löst Gleichungen oder Gleichungssysteme|`solve(x**2 - 4, x)` → `[ -2, 2 ]`|
|
||||
||`Eq()`|Erstellt eine symbolische Gleichung|`Eq(x + y, 2)`|
|
||||
|**Differentialrechnung**|`diff()`|Berechnet die Ableitung|`diff(x**2, x)` → `2*x`|
|
||||
||`integrate()`|Berechnet das Integral|`integrate(x, x)` → `x**2/2`|
|
||||
|**Vereinfachung**|`simplify()`|Vereinfacht einen Ausdruck|`simplify((x**2 - 1)/(x - 1))` → `x + 1`|
|
||||
||`expand()`|Erweitert einen Ausdruck|`expand((x + 1)**2)` → `x**2 + 2*x + 1`|
|
||||
||`factor()`|Faktorisierte einen Ausdruck|`factor(x**2 - 1)` → `(x - 1)*(x + 1)`|
|
||||
|**Lösungen**|`nsolve()`|Numerische Lösung für Gleichungen|`nsolve(x**2 - 2, x, 1.5)` → `1.414213562373095`|
|
||||
|**Reihen und Summen**|`summation()`|Berechnet die Summe einer Reihe|`summation(n, (n, 1, 10))` → `55`|
|
||||
||`limit()`|Berechnet den Grenzwert|`limit(sin(x)/x, x, 0)` → `1`|
|
||||
|**Matrixalgebra**|`Matrix()`|Erstellt eine symbolische Matrix|`Matrix([[1, 2], [3, 4]])`|
|
||||
||`.inv()`|Berechnet die Inverse einer Matrix|`Matrix([[1, 2], [3, 4]]).inv()`|
|
||||
|**Substitution**|`.subs()`|Ersetzt Symbole durch Werte oder andere Ausdrücke|`(x + y).subs(x, 2)` → `2 + y`|
|
||||
|**Plotten**|`plot()`|Erstellt einfache Plots|`plot(x**2, (x, -5, 5))`|
|
||||
|**Weitere Funktionen**|`latex()`|Konvertiert einen Ausdruck in LaTeX-Format|`latex(x**2 + y**2)` → `'x^{2} + y^{2}'`|
|
||||
||`pretty()`|Gibt einen "schönen" String des Ausdrucks aus|`pretty(x**2 + y)`|
|
||||
|
||||
---
|
||||
|
||||
## NumPy Merkhilfe
|
||||
|
||||
|**Kategorie**|**Funktion/Method**|**Beschreibung**|**Beispiel**|
|
||||
|---|---|---|---|
|
||||
|**Array-Erstellung**|`np.array()`|Erstellt ein Array aus einer Liste oder Tupel|`np.array([1, 2, 3])`|
|
||||
||`np.zeros()`|Erstellt ein Array gefüllt mit Nullen|`np.zeros((2,3))`|
|
||||
||`np.ones()`|Erstellt ein Array gefüllt mit Einsen|`np.ones(5)`|
|
||||
||`np.arange()`|Erstellt ein Array mit einer Sequenz von Zahlen|`np.arange(0, 10, 2)` → `array([0, 2, 4, 6, 8])`|
|
||||
||`np.linspace()`|Erstellt ein Array mit gleichmäßig verteilten Werten|`np.linspace(0, 1, 5)` → `array([0. , 0.25, 0.5, 0.75, 1. ])`|
|
||||
|**Grundlegende Operationen**|`+`, `-`, `*`, `/`|Elementweise Addition, Subtraktion, Multiplikation, Division|`a + b`, `a * 2`|
|
||||
||`np.dot()`|Berechnet das Skalarprodukt zweier Arrays|`np.dot(a, b)`|
|
||||
||`np.transpose()`|Transponiert ein Array|`a.T`|
|
||||
|**Indexierung & Slicing**|`a[i]`, `a[i:j]`|Zugriff auf Elemente oder Teilbereiche des Arrays|`a[0]`, `a[1:3]`|
|
||||
|**Statistische Funktionen**|`np.mean()`|Berechnet den Mittelwert|`np.mean(a)`|
|
||||
||`np.median()`|Berechnet den Median|`np.median(a)`|
|
||||
||`np.std()`|Berechnet die Standardabweichung|`np.std(a)`|
|
||||
|**Lineare Algebra**|`np.linalg.inv()`|Berechnet die Inverse einer Matrix|`np.linalg.inv(A)`|
|
||||
||`np.linalg.det()`|Berechnet die Determinante einer Matrix|`np.linalg.det(A)`|
|
||||
||`np.linalg.eig()`|Berechnet Eigenwerte und Eigenvektoren|`np.linalg.eig(A)`|
|
||||
|**Broadcasting**|-|Ermöglicht Operationen auf Arrays unterschiedlicher Formen|`a + np.array([1, 2, 3])`|
|
||||
|**Reshaping**|`np.reshape()`|Ändert die Form eines Arrays ohne Daten zu ändern|`a.reshape((3, 2))`|
|
||||
||`np.flatten()`|Konvertiert ein mehrdimensionales Array in ein eindimensionales Array|`a.flatten()`|
|
||||
|**Random Module**|`np.random.rand()`|Erstellt ein Array mit zufälligen Werten aus einer gleichverteilten Verteilung|`np.random.rand(3,2)`|
|
||||
||`np.random.randint()`|Erstellt ein Array mit zufälligen Ganzzahlen|`np.random.randint(0, 10, (2,3))`|
|
||||
||`np.random.seed()`|Setzt den Seed für reproduzierbare Zufallszahlen|`np.random.seed(42)`|
|
||||
|**Mathematische Funktionen**|`np.sin()`, `np.cos()`, `np.exp()`, `np.log()`|Wendet mathematische Funktionen elementweise auf Arrays an|`np.sin(a)`, `np.exp(a)`|
|
||||
|**Aggregation**|`np.sum()`|Berechnet die Summe aller Elemente|`np.sum(a)`|
|
||||
||`np.prod()`|Berechnet das Produkt aller Elemente|`np.prod(a)`|
|
||||
||`np.cumsum()`|Berechnet die kumulative Summe|`np.cumsum(a)`|
|
||||
|**Sortieren**|`np.sort()`|Sortiert ein Array|`np.sort(a)`|
|
||||
|**Speicher & Datentypen**|`a.dtype`|Gibt den Datentyp des Arrays an|`a.dtype`|
|
||||
||`a.astype()`|Ändert den Datentyp eines Arrays|`a.astype(float)`|
|
||||
|**Dateioperationen**|`np.loadtxt()`|Lädt Daten aus einer Textdatei in ein Array|`np.loadtxt('data.txt')`|
|
||||
||`np.savetxt()`|Speichert ein Array in eine Textdatei|`np.savetxt('output.txt', a)`|
|
||||
|**Weitere nützliche Funktionen**|`np.concatenate()`|Verbindet zwei Arrays entlang einer bestehenden Achse|`np.concatenate((a, b), axis=0)`|
|
||||
||`np.split()`|Teilt ein Array in mehrere Teilarrays|`np.split(a, 2)`|
|
||||
@@ -0,0 +1,197 @@
|
||||
import streamlit as st
|
||||
import math
|
||||
import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def calculate_formula(with_replacement, ordered):
|
||||
if with_replacement:
|
||||
if ordered:
|
||||
formula = f"n^k"
|
||||
else:
|
||||
formula = f"Binomialkoeffizient (n + k - 1 über k)"
|
||||
else:
|
||||
if ordered:
|
||||
formula = f"P(n, k) = n! / (n - k)!"
|
||||
else:
|
||||
formula = f"C(n, k) = n! / (k! (n - k)!)"
|
||||
return formula
|
||||
|
||||
def calculate_number_of_possibilities(with_replacement, ordered, n, k):
|
||||
if with_replacement:
|
||||
if ordered:
|
||||
return n ** k
|
||||
else:
|
||||
return math.comb(n + k - 1, k)
|
||||
else:
|
||||
if ordered:
|
||||
return math.perm(n, k)
|
||||
else:
|
||||
return math.comb(n, k)
|
||||
|
||||
def build_tree(n, k, with_replacement, ordered):
|
||||
G = nx.DiGraph()
|
||||
G.add_node("Start")
|
||||
# Queue enthält Tupel aus (current_node, used_elements, last_selected)
|
||||
queue = [("Start", [], 0)] # (current_node, used_elements, last_selected)
|
||||
|
||||
for depth in range(1, min(k + 1, 4)): # Limit auf 3 Schichten
|
||||
next_queue = []
|
||||
for node, used, last_selected in queue:
|
||||
for i in range(1, n + 1):
|
||||
if not with_replacement:
|
||||
if i in used:
|
||||
# Ohne Zurücklegen und Element bereits verwendet: Eliminiert
|
||||
child_label = f"{node}->{i} (elim)"
|
||||
G.add_node(child_label)
|
||||
G.add_edge(node, child_label)
|
||||
continue
|
||||
|
||||
if not ordered:
|
||||
if depth == 1:
|
||||
# Im ersten Schritt gibt es keine Einschränkungen
|
||||
pass
|
||||
else:
|
||||
# Bei Kombinationen: nur Elemente >= dem letzten ausgewählten Element
|
||||
if i < last_selected:
|
||||
# Diese Auswahl würde eine Permutation darstellen, die wir bei Kombinationen vermeiden
|
||||
child_label = f"{node}->{i} (elim)"
|
||||
G.add_node(child_label)
|
||||
G.add_edge(node, child_label)
|
||||
continue
|
||||
|
||||
# Gültige Auswahl
|
||||
if with_replacement:
|
||||
new_used = used.copy()
|
||||
else:
|
||||
new_used = used.copy()
|
||||
new_used.append(i)
|
||||
child_label = f"{node}->{i}"
|
||||
G.add_node(child_label)
|
||||
G.add_edge(node, child_label)
|
||||
next_queue.append((child_label, new_used, i))
|
||||
queue = next_queue
|
||||
return G
|
||||
|
||||
def hierarchy_pos(G, root=None, width=1.0, vert_gap=0.2, vert_loc=0, xcenter=0.5, pos=None, parent=None, parsed=None):
|
||||
"""
|
||||
Hierarchical layout für einen Baum, mit der Wurzel oben.
|
||||
Optimiert die horizontale Verteilung basierend auf der Anzahl der Unterknoten.
|
||||
"""
|
||||
if pos is None:
|
||||
pos = {}
|
||||
if parsed is None:
|
||||
parsed = set()
|
||||
|
||||
if root is None:
|
||||
root = "Start"
|
||||
|
||||
children = list(G.successors(root))
|
||||
if not children:
|
||||
pos[root] = (xcenter, vert_loc)
|
||||
else:
|
||||
# Anzahl der Kinder
|
||||
num_children = len(children)
|
||||
# Gesamte Breite für die Kinder
|
||||
dx = width / num_children
|
||||
next_x = xcenter - width / 2
|
||||
for child in children:
|
||||
next_x += dx
|
||||
pos = hierarchy_pos(G, child, width=dx, vert_gap=vert_gap, vert_loc=vert_loc - vert_gap, xcenter=next_x, pos=pos, parent=root, parsed=parsed)
|
||||
pos[root] = (xcenter, vert_loc)
|
||||
return pos
|
||||
|
||||
def plot_tree(G, show_eliminated, with_replacement, ordered, n, k):
|
||||
pos = hierarchy_pos(G)
|
||||
plt.figure(figsize=(12, 8))
|
||||
ax = plt.gca()
|
||||
ax.set_axis_off()
|
||||
|
||||
# Bestimme welche Knoten gezeichnet werden sollen
|
||||
if show_eliminated:
|
||||
nodes_to_draw = list(G.nodes())
|
||||
else:
|
||||
nodes_to_draw = [node for node in G.nodes() if "(elim)" not in node]
|
||||
|
||||
# Bestimme welche Kanten gezeichnet werden sollen
|
||||
edges_to_draw = []
|
||||
for edge in G.edges():
|
||||
source, target = edge
|
||||
if show_eliminated:
|
||||
edges_to_draw.append(edge)
|
||||
else:
|
||||
if "(elim)" not in target:
|
||||
edges_to_draw.append(edge)
|
||||
|
||||
# Bestimme Farben
|
||||
node_colors = []
|
||||
for node in nodes_to_draw:
|
||||
if node == "Start":
|
||||
color = 'black'
|
||||
elif '->' in node:
|
||||
if "(elim)" in node:
|
||||
color = 'red'
|
||||
else:
|
||||
color = 'blue'
|
||||
else:
|
||||
color = 'black'
|
||||
node_colors.append(color)
|
||||
|
||||
# Zeichne Knoten
|
||||
nx.draw_networkx_nodes(G, pos, nodelist=nodes_to_draw, node_color=node_colors, node_size=500, alpha=0.9)
|
||||
|
||||
# Zeichne Kanten
|
||||
nx.draw_networkx_edges(G, pos, edgelist=edges_to_draw, arrows=True, arrowstyle='->', arrowsize=20)
|
||||
|
||||
# Zeichne Labels
|
||||
labels = {}
|
||||
for node in nodes_to_draw:
|
||||
if node == "Start":
|
||||
labels[node] = "Start"
|
||||
else:
|
||||
# Entferne "(elim)" für die Anzeige, wenn eliminiert ist
|
||||
label = node.replace("Start->", "").replace("->", "\n→ ")
|
||||
if "(elim)" in label:
|
||||
label = label.replace(" (elim)", "")
|
||||
labels[node] = label
|
||||
nx.draw_networkx_labels(G, pos, labels=labels, font_size=10, font_weight='bold')
|
||||
|
||||
st.pyplot(plt)
|
||||
plt.close()
|
||||
|
||||
def main():
|
||||
st.title("Interaktives Lerntool für Kombinatorische Formeln")
|
||||
|
||||
st.sidebar.header("Einstellungen")
|
||||
|
||||
with_replacement = st.sidebar.checkbox("Mit Zurücklegen", value=False)
|
||||
ordered = st.sidebar.checkbox("Berücksichtigung der Reihenfolge", value=False)
|
||||
|
||||
st.sidebar.header("Parameter")
|
||||
n = st.sidebar.number_input("Anzahl der Elemente (n)", min_value=1, value=5, step=1)
|
||||
k = st.sidebar.number_input("Anzahl der Auswahlen (k)", min_value=1, value=3, step=1)
|
||||
|
||||
formula = calculate_formula(with_replacement, ordered)
|
||||
st.subheader("Entsprechende Formel")
|
||||
st.write(formula)
|
||||
|
||||
num_possibilities = calculate_number_of_possibilities(with_replacement, ordered, n, k)
|
||||
st.subheader("Anzahl der Möglichkeiten")
|
||||
st.write(f"Anzahl der Möglichkeiten: {num_possibilities}")
|
||||
|
||||
st.subheader("Baumdarstellung (erste 3 Schichten)")
|
||||
G = build_tree(n, k, with_replacement, ordered)
|
||||
|
||||
show_eliminated = st.checkbox("Eliminierte Möglichkeiten anzeigen", value=True)
|
||||
plot_tree(G, show_eliminated, with_replacement, ordered, n, k)
|
||||
|
||||
st.markdown("""
|
||||
---
|
||||
**Hinweise:**
|
||||
- *Mit Zurücklegen*: Elemente können mehrfach ausgewählt werden.
|
||||
- *Berücksichtigung der Reihenfolge*: Reihenfolge der Auswahl ist wichtig.
|
||||
- *Baumdarstellung*: Zeigt die ersten 3 Schichten der Auswahlmöglichkeiten.
|
||||
- *Eliminierte Möglichkeiten*: Elemente, die aufgrund der Einstellungen nicht zulässig sind, werden rot markiert.
|
||||
""")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,235 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "e15757ea0cf743dc9af162093423cb6e",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"VBox(children=(HBox(children=(Dropdown(description='Regel:', options=('Kombination', 'Permutation', 'Fakultät'…"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import numpy as np\n",
|
||||
"import ipywidgets as widgets\n",
|
||||
"from IPython.display import display, Math, clear_output\n",
|
||||
"\n",
|
||||
"# Interaktives Lern-Tool für Kombinatorik-Regeln\n",
|
||||
"# Dies ist ein Jupyter-Notebook-Style Code für interaktive Widgets.\n",
|
||||
"# Bitte in einer Umgebung ausführen, die Widgets unterstützt (z.B. JupyterLab/Notebook).\n",
|
||||
"\n",
|
||||
"# Funktionen zur Berechnung\n",
|
||||
"def combination(n, k):\n",
|
||||
" from math import comb\n",
|
||||
" return comb(n, k)\n",
|
||||
"\n",
|
||||
"def permutation(n, k):\n",
|
||||
" from math import perm\n",
|
||||
" return perm(n, k)\n",
|
||||
"\n",
|
||||
"def factorial(n):\n",
|
||||
" from math import factorial\n",
|
||||
" return factorial(n)\n",
|
||||
"\n",
|
||||
"def binomial_coefficient(n, k):\n",
|
||||
" from math import comb\n",
|
||||
" return comb(n, k)\n",
|
||||
"\n",
|
||||
"def variation(n, k):\n",
|
||||
" from math import perm\n",
|
||||
" return perm(n, k)\n",
|
||||
"\n",
|
||||
"def multiset_combination(n, k):\n",
|
||||
" from math import comb\n",
|
||||
" return comb(n + k - 1, k)\n",
|
||||
"\n",
|
||||
"# Funktion, um den Entscheidungsbaum zu zeichnen (nur für Kombinationen und Permutationen)\n",
|
||||
"def draw_tree(n, k, is_perm):\n",
|
||||
" plt.figure(figsize=(8, 6))\n",
|
||||
" ax = plt.gca()\n",
|
||||
" ax.clear()\n",
|
||||
" ax.set_title(\"Entscheidungsbaum\", fontsize=14)\n",
|
||||
" ax.axis('off')\n",
|
||||
"\n",
|
||||
" if k == 1:\n",
|
||||
" x_start = 0.5\n",
|
||||
" y_start = 0.9\n",
|
||||
" plt.text(x_start, y_start, f\"Start\\n(n={n})\", ha='center', va='center')\n",
|
||||
" for i in range(n):\n",
|
||||
" x = 0.1 + i*(0.8/(n-1)) if n > 1 else 0.5\n",
|
||||
" y = 0.6\n",
|
||||
" plt.plot([x_start, x], [y_start-0.05, y], 'k-')\n",
|
||||
" plt.text(x, y, f\"Wahl {i+1}\", ha='center', va='center')\n",
|
||||
"\n",
|
||||
" elif k == 2:\n",
|
||||
" x_start = 0.5\n",
|
||||
" y_start = 0.9\n",
|
||||
" plt.text(x_start, y_start, f\"Start\\n(n={n})\", ha='center', va='center')\n",
|
||||
" child_coords = []\n",
|
||||
" for i in range(n):\n",
|
||||
" x = 0.1 + i*(0.8/(n-1)) if n > 1 else 0.5\n",
|
||||
" y = 0.7\n",
|
||||
" plt.plot([x_start, x], [y_start-0.05, y], 'k-')\n",
|
||||
" plt.text(x, y, f\"W1={i+1}\", ha='center', va='center')\n",
|
||||
" child_coords.append((x, y))\n",
|
||||
" for (ix, iy) in child_coords:\n",
|
||||
" branch_count = (n-1) if is_perm else (n)\n",
|
||||
" for j in range(branch_count):\n",
|
||||
" x2 = ix - 0.08 + j*(0.16/(branch_count-1)) if branch_count > 1 else ix\n",
|
||||
" y2 = 0.45\n",
|
||||
" plt.plot([ix, x2], [iy-0.05, y2], 'k-')\n",
|
||||
" plt.text(x2, y2, f\"W2={j+1}\", ha='center', va='center', fontsize=8)\n",
|
||||
" elif k == 3:\n",
|
||||
" x_start = 0.5\n",
|
||||
" y_start = 0.95\n",
|
||||
" plt.text(x_start, y_start, f\"Start\\n(n={n})\", ha='center', va='center')\n",
|
||||
" layer1 = []\n",
|
||||
" for i in range(n):\n",
|
||||
" x = 0.1 + i*(0.8/(n-1)) if n > 1 else 0.5\n",
|
||||
" y = 0.8\n",
|
||||
" plt.plot([x_start, x], [y_start-0.03, y], 'k-')\n",
|
||||
" plt.text(x, y, f\"W1={i+1}\", ha='center', va='center', fontsize=9)\n",
|
||||
" layer1.append((x, y))\n",
|
||||
" layer2 = []\n",
|
||||
" for (ix, iy) in layer1:\n",
|
||||
" branch_count = (n-1) if is_perm else n\n",
|
||||
" for j in range(branch_count):\n",
|
||||
" x2 = ix - 0.05 + j*(0.1/(branch_count-1)) if branch_count > 1 else ix\n",
|
||||
" y2 = 0.6\n",
|
||||
" plt.plot([ix, x2], [iy-0.03, y2], 'k-')\n",
|
||||
" plt.text(x2, y2, f\"W2={j+1}\", ha='center', va='center', fontsize=7)\n",
|
||||
" layer2.append((x2, y2))\n",
|
||||
" for (ix2, iy2) in layer2:\n",
|
||||
" branch_count = (n-2) if is_perm else n\n",
|
||||
" for j in range(branch_count):\n",
|
||||
" x3 = ix2 - 0.02 + j*(0.04/(branch_count-1)) if branch_count > 1 else ix2\n",
|
||||
" y3 = 0.4\n",
|
||||
" plt.plot([ix2, x3], [iy2-0.03, y3], 'k-')\n",
|
||||
" plt.text(x3, y3, f\"W3={j+1}\", ha='center', va='center', fontsize=6)\n",
|
||||
" else:\n",
|
||||
" plt.text(0.5, 0.5, \"Baumdiagramm für k>3 ist zu groß.\\nBitte k <= 3 für Baum\", ha='center', va='center', fontsize=12)\n",
|
||||
"\n",
|
||||
" plt.tight_layout()\n",
|
||||
" plt.show()\n",
|
||||
"\n",
|
||||
"# Widgets erstellen\n",
|
||||
"dropdown_rule = widgets.Dropdown(\n",
|
||||
" options=['Kombination', 'Permutation', 'Fakultät', 'Binomialkoeffizient', 'Variation', 'Mehrfachkombination'],\n",
|
||||
" value='Kombination',\n",
|
||||
" description='Regel:',\n",
|
||||
" style={'description_width': 'initial'}\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"input_n = widgets.IntText(value=5, description='n:', style={'description_width': 'initial'})\n",
|
||||
"input_k = widgets.IntText(value=2, description='k:', style={'description_width': 'initial'})\n",
|
||||
"input_k.layout.visibility = 'visible' # Standardmäßig sichtbar\n",
|
||||
"\n",
|
||||
"output_area = widgets.Output()\n",
|
||||
"\n",
|
||||
"# Button zum Berechnen\n",
|
||||
"button = widgets.Button(description='Berechnen & Visualisieren')\n",
|
||||
"\n",
|
||||
"# Callback-Funktion\n",
|
||||
"def on_button_click(b):\n",
|
||||
" with output_area:\n",
|
||||
" clear_output()\n",
|
||||
" rule = dropdown_rule.value\n",
|
||||
" n = input_n.value\n",
|
||||
" k = input_k.value if rule in ['Kombination', 'Permutation', 'Binomialkoeffizient', 'Variation', 'Mehrfachkombination'] else None\n",
|
||||
"\n",
|
||||
" try:\n",
|
||||
" if rule == 'Kombination':\n",
|
||||
" if k > n:\n",
|
||||
" print(\"k darf nicht größer als n sein.\")\n",
|
||||
" return\n",
|
||||
" res = combination(n, k)\n",
|
||||
" display(Math(r\"C(n,k) = \\binom{{{}}}{{{}}} = {}\".format(n, k, res)))\n",
|
||||
" draw_tree(n, k, is_perm=False)\n",
|
||||
" elif rule == 'Permutation':\n",
|
||||
" if k > n:\n",
|
||||
" print(\"k darf nicht größer als n sein.\")\n",
|
||||
" return\n",
|
||||
" res = permutation(n, k)\n",
|
||||
" display(Math(r\"P(n,k) = {} = {}\".format(res, res)))\n",
|
||||
" draw_tree(n, k, is_perm=True)\n",
|
||||
" elif rule == 'Fakultät':\n",
|
||||
" res = factorial(n)\n",
|
||||
" display(Math(r\"n! = {} = {}\".format(res, res)))\n",
|
||||
" elif rule == 'Binomialkoeffizient':\n",
|
||||
" if k > n:\n",
|
||||
" print(\"k darf nicht größer als n sein.\")\n",
|
||||
" return\n",
|
||||
" res = binomial_coefficient(n, k)\n",
|
||||
" display(Math(r\"\\binom{{{}}}{{{}}} = {}\".format(n, k, res)))\n",
|
||||
" elif rule == 'Variation':\n",
|
||||
" if k > n:\n",
|
||||
" print(\"k darf nicht größer als n sein.\")\n",
|
||||
" return\n",
|
||||
" res = variation(n, k)\n",
|
||||
" display(Math(r\"V(n,k) = P(n,k) = {} = {}\".format(res, res)))\n",
|
||||
" elif rule == 'Mehrfachkombination':\n",
|
||||
" res = multiset_combination(n, k)\n",
|
||||
" display(Math(r\"\\binom{{n+k-1}}{{k}} = {} = {}\".format(res, res)))\n",
|
||||
" else:\n",
|
||||
" print(\"Unbekannte Regel.\")\n",
|
||||
" except Exception as e:\n",
|
||||
" print(f\"Fehler: {e}\")\n",
|
||||
"\n",
|
||||
"# Event verknüpfen\n",
|
||||
"button.on_click(on_button_click)\n",
|
||||
"\n",
|
||||
"# Anpassung der sichtbaren Eingabefelder basierend auf der gewählten Regel\n",
|
||||
"def on_rule_change(change):\n",
|
||||
" rule = change['new']\n",
|
||||
" if rule in ['Kombination', 'Permutation', 'Binomialkoeffizient', 'Variation', 'Mehrfachkombination']:\n",
|
||||
" input_k.layout.visibility = 'visible'\n",
|
||||
" else:\n",
|
||||
" input_k.layout.visibility = 'hidden'\n",
|
||||
"\n",
|
||||
"dropdown_rule.observe(on_rule_change, names='value')\n",
|
||||
"\n",
|
||||
"# Anzeige\n",
|
||||
"controls = widgets.VBox([\n",
|
||||
" widgets.HBox([dropdown_rule]),\n",
|
||||
" widgets.HBox([input_n, input_k]),\n",
|
||||
" button,\n",
|
||||
" output_area\n",
|
||||
"])\n",
|
||||
"display(controls)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
s = """
|
||||
CREATE TABLE kunde
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
name CHARACTER VARYING NOT NULL,
|
||||
email CHARACTER VARYING NOT NULL,
|
||||
password CHARACTER VARYING NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE bestellung
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
kunde_id INTEGER NOT NULL,
|
||||
datum DATE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE produkt
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
name CHARACTER VARYING NOT NULL,
|
||||
beschreibung CHARACTER VARYING NOT NULL,
|
||||
anzahl INTEGER NOT NULL,
|
||||
preis NUMERIC(8,2) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE bestellung_produkt
|
||||
(
|
||||
bestellung_id INTEGER NOT NULL,
|
||||
produkt_id INTEGER NOT NULL,
|
||||
anzahl INTEGER NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
for command in s.split(';'):
|
||||
print(command)
|
||||
print('-----------------------')
|
||||
Reference in new issue
Block a user