Hong-Phuc Bui
2024-05-05 5b8b6be22c49d62726f9e28fb57f6c32835900e9
Beispiel Projekt
2 files modified
4 files added
110 ■■■■ changed files
python-grundlage/dice-simulation.py 16 ●●●●● patch | view | raw | blame | history
python-grundlage/permutation-iterative.py 26 ●●●● patch | view | raw | blame | history
python-grundlage/petal.py 32 ●●●●● patch | view | raw | blame | history
python-grundlage/three-sort.py 16 ●●●●● patch | view | raw | blame | history
python-grundlage/valide-credits.txt 16 ●●●●● patch | view | raw | blame | history
python-grundlage/weekdays.py 4 ●●●● patch | view | raw | blame | history
python-grundlage/dice-simulation.py
New file
@@ -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)
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
python-grundlage/petal.py
New file
@@ -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()
python-grundlage/three-sort.py
New file
@@ -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)
python-grundlage/valide-credits.txt
New file
@@ -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
python-grundlage/weekdays.py
@@ -1,3 +1,7 @@
for t in range(0,7):
    s = (7 - t) % 7 + 1
    print(f"{t} → {s}")