2 files modified
9 files added
New file |
| | |
| | | #! /usr/bin/env python |
| | | |
| | | from typing import Final |
| | | import sys |
| | | |
| | | n = int(sys.argv[1]) |
| | | power = 1 |
| | | LIMIT: Final[int] = n // 2 |
| | | |
| | | # find the largest power of 2, which is less than or equal to n/2 |
| | | while power <= LIMIT: |
| | | power *= 2 |
| | | |
| | | binary_presentation = "" |
| | | while power > 0: |
| | | if n < power: |
| | | binary_presentation += "0" |
| | | else: |
| | | binary_presentation += "1" |
| | | n -= power |
| | | power //= 2 |
| | | print(binary_presentation) |
New file |
| | |
| | | import sys |
| | | |
| | | a = int(sys.argv[1]) |
| | | b = int(sys.argv[2]) |
| | | s = a + b |
| | | |
| | | print(s) |
New file |
| | |
| | | #! /usr/bin/env python |
| | | |
| | | import sys |
| | | |
| | | a = int(sys.argv[1]) |
| | | b = int(sys.argv[2]) |
| | | |
| | | while b != 0: |
| | | t = b |
| | | b = a % b |
| | | a = t |
| | | |
| | | print(a) |
| | |
| | | # Credit: https://stackoverflow.com/a/57579379 |
| | | |
| | | import sys |
| | | |
| | | eps = 1.0 |
| | | while eps + 1 > 1: |
| | | eps /= 2 |
| | | eps *= 2 |
| | | sys_eps = sys.float_info.epsilon |
| | | |
| | | eps = 1.0 |
| | | while 1.0 + eps > 1.0: |
| | | eps /= 2.0 |
| | | eps *= 2.0 |
| | | |
| | | print(f"The calculated epsilon: {eps}") |
| | | print(f" The system epsilon: {sys_eps}") |
| | | |
| | | # with assign expression |
| | | eps = 1.0 |
| | | while 1.0 + (eps := eps / 2.0) > 1.0: pass |
| | | eps *= 2.0 |
| | | |
| | | print(f"The calculated epsilon: {eps}") |
| | | print(f" The system epsilon: {sys_eps}") |
New file |
| | |
| | | n = 10 |
| | | h = 1 |
| | | algebraic_h = "1" |
| | | |
| | | for k in range(2, n+2): |
| | | print(f"{algebraic_h} = {h}") |
| | | algebraic_h = f"{algebraic_h} + 1/{k}" |
| | | h = h + 1/k |
| | | |
New file |
| | |
| | | #! /usr/bin/env python |
| | | # -*-encoding utf-8-*- |
| | | |
| | | n = 0xF |
| | | |
| | | for i in range(n + 1): |
| | | for j in range(n + 1): |
| | | p = i * j |
| | | print(f"{p:02X} ", end="") |
| | | print() |
New file |
| | |
| | | #! /usr/bin/env python |
| | | 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) |
| | | |
| | | permutations = [[]] |
| | | element = n - 1 |
| | | |
| | | while element >= 0: |
| | | next_permutations = [] |
| | | for p in permutations: |
| | | for position in range(len(p), -1, -1): |
| | | new_permutation = p.copy() |
| | | new_permutation.insert(position, element) |
| | | next_permutations.append(new_permutation) |
| | | permutations = next_permutations |
| | | element -= 1 |
| | | |
| | | print(permutations) |
New file |
| | |
| | | #! /usr/bin/env python |
| | | import sys |
| | | n = int(sys.argv[1]) |
| | | |
| | | # quote_test ist ein 2-er Tupel (q, r) |
| | | while (quote_rest := divmod(n, 2)) and quote_rest[1] == 0: |
| | | print(f"{2} ", end="") |
| | | n = quote_rest[0] |
| | | |
| | | p = 3 |
| | | while p * p <= n: |
| | | if (quote_rest := divmod(n, p)) and quote_rest[1] == 0: |
| | | print(f"{p} ", end="") |
| | | n = quote_rest[0] |
| | | else: |
| | | p += 2 |
| | | if n != 1: |
| | | print(n) |
| | | |
| | | #print(f"iteration: {__iteration}") |
| | | |
New file |
| | |
| | | #! /usr/bin/env python |
| | | # -*-encoding utf-8-*- |
| | | |
| | | import sys |
| | | |
| | | n = int(sys.argv[1]) |
| | | p = 2 |
| | | |
| | | iteration = 0 |
| | | while n > 1: |
| | | q, r = divmod(n, p) |
| | | if r == 0: |
| | | print(f"{p} ", end="") |
| | | n = q |
| | | else: |
| | | p += 1 |
| | | iteration += 1 |
| | | |
| | | print(f"\niteration: {iteration}") |
| | | |
old mode 100644
new mode 100755
| | |
| | | #! /usr/bin/env python |
| | | import sys |
| | | from typing import Final |
| | | |
| | | n = float(sys.argv[1]) |
| | | EPSILON = sys.float_info.epsilon |
| | | EPSILON: Final[float] = sys.float_info.epsilon |
| | | |
| | | t = n |
| | | while abs(t - n/t) > (EPSILON*t): |
| | | t = (n / t + t) / 2 |
| | | x = n # !$x_0 = n$! |
| | | while abs(x - (q := n / x)) > (EPSILON * x): # !$\left|\frac{x^2-n}{x^2}\right| > \varepsilon $! |
| | | x = (x + q) / 2.0 # !$x_{i+1} = \frac{1}{2}(x_i + \frac{n}{x_i})$! |
| | | |
| | | print(f"sqrt({n}) ~= {t}") |
| | | print(f"sqrt({n}) ~ {x}") |