From 5b8b6be22c49d62726f9e28fb57f6c32835900e9 Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Sun, 05 May 2024 23:36:37 +0200
Subject: [PATCH] Beispiel Projekt
---
python-grundlage/three-sort.py | 16 ++++++++
python-grundlage/petal.py | 32 ++++++++++++++++
python-grundlage/dice-simulation.py | 16 ++++++++
python-grundlage/permutation-iterative.py | 26 +++++++------
python-grundlage/valide-credits.txt | 16 ++++++++
python-grundlage/weekdays.py | 4 ++
6 files changed, 98 insertions(+), 12 deletions(-)
diff --git a/python-grundlage/dice-simulation.py b/python-grundlage/dice-simulation.py
new file mode 100644
index 0000000..b02256e
--- /dev/null
+++ b/python-grundlage/dice-simulation.py
@@ -0,0 +1,16 @@
+#! /usr/bin/evn python
+import random
+
+random.seed(5643)
+experiments = 500
+dice_roll = tuple(random.randint(1, 6) for r in range(0, experiments))
+absolute_frequency = tuple((face, len([f for f in dice_roll if f == face]))
+ for face in range(1, 6 + 1)
+ )
+print(absolute_frequency)
+
+relative_frequency = tuple(
+ (f[0], f[1]/experiments) for f in absolute_frequency
+)
+
+print(relative_frequency)
diff --git a/python-grundlage/permutation-iterative.py b/python-grundlage/permutation-iterative.py
index 8b4030c..8a686ec 100755
--- a/python-grundlage/permutation-iterative.py
+++ b/python-grundlage/permutation-iterative.py
@@ -2,18 +2,20 @@
import sys
n = int(sys.argv[1])
-
-# permutations = [[0]]
-# element = 1
-# n = 2
-#
-# next_permutations = []
-# for p in permutations:
-# for position in range(0, len(p) + 1):
-# new_permutation = p.copy()
-# new_permutation.insert(position, element)
-# next_permutations.append(new_permutation)
-# print(next_permutations)
+"""
+function permutation(set: []) -> []
+ if size(set) < 2 return [set];
+ result = []
+ for idx, e in set:
+ other_elements = set \ {e}
+ other_permutations = permutation(other_elements)
+ for p in other_permutations:
+ result.append( [e].concat(p) )
+ end
+ end
+ return result
+end
+"""
permutations = [[]]
element = n - 1
diff --git a/python-grundlage/petal.py b/python-grundlage/petal.py
new file mode 100644
index 0000000..76e0ec4
--- /dev/null
+++ b/python-grundlage/petal.py
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+import turtle
+import math
+
+num_of_petal = 60
+petal_length = 100
+# winkel sind in Degree
+alpha = 90 / num_of_petal
+beta = 2 * alpha
+gamma = 180 - beta
+
+# abgeleitete Länge
+side_length = petal_length * math.cos(math.radians(alpha))
+
+for petal in range(0, num_of_petal):
+ direction = petal * (360 / num_of_petal)
+ turtle.home()
+ turtle.left(direction + alpha)
+ turtle.fd(side_length)
+ turtle.right(beta)
+ turtle.fd(side_length)
+ turtle.right(gamma)
+ turtle.fd(side_length)
+ turtle.right(beta)
+ turtle.fd(side_length)
+
+turtle.done()
+
+
+
+
+
diff --git a/python-grundlage/three-sort.py b/python-grundlage/three-sort.py
new file mode 100644
index 0000000..bcec2b4
--- /dev/null
+++ b/python-grundlage/three-sort.py
@@ -0,0 +1,16 @@
+import sys
+a = int(sys.argv[1])
+b = int(sys.argv[2])
+c = int(sys.argv[3])
+
+if a < b:
+ first, second = a, b
+else:
+ first, second = b, a
+
+if c < first:
+ print(c, first, second)
+elif c > second:
+ print(first, second, c)
+else:
+ print(first, c , second)
\ No newline at end of file
diff --git a/python-grundlage/valide-credits.txt b/python-grundlage/valide-credits.txt
new file mode 100644
index 0000000..2fc0e50
--- /dev/null
+++ b/python-grundlage/valide-credits.txt
@@ -0,0 +1,16 @@
+American Express 378282246310005
+American Express 371449635398431
+American Express Corporate 378734493671000
+Diners Club 30569309025904
+Discover 6011111111111117
+Discover 6011000990139424
+JCB 3530111333300000
+JCB 3566002020360505
+MasterCard 2221000000000009
+MasterCard 2223000048400011
+MasterCard 2223016768739313
+MasterCard 5555555555554444
+MasterCard 5105105105105100
+Visa 4111111111111111
+Visa 4012888888881881
+Visa 4222222222222
diff --git a/python-grundlage/weekdays.py b/python-grundlage/weekdays.py
index ed9543c..c3e300f 100644
--- a/python-grundlage/weekdays.py
+++ b/python-grundlage/weekdays.py
@@ -1,3 +1,7 @@
for t in range(0,7):
s = (7 - t) % 7 + 1
print(f"{t} → {s}")
+
+
+
+
--
Gitblit v1.10.0