From 71d87423fe7f8c282b5f58a0b1fb76a5d3274953 Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Fri, 22 Oct 2021 15:29:01 +0200 Subject: [PATCH] =?UTF-8?q?master=20>=20master:=20=20code=20-=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/__init__.py | 0 code/local/__init__.py | 0 code/local/maths.py | 9 ++++++++ code/local/misc.py | 9 ++++++++ code/local/system.py | 14 ++++++++++++ code/local/typing.py | 19 ++++++++++++++++ code/main.py | 49 +++++++++++++++++++++++++++++++++++++++++ code/search/__init__.py | 0 code/search/exports.py | 8 +++++++ code/search/methods.py | 40 +++++++++++++++++++++++++++++++++ 10 files changed, 148 insertions(+) create mode 100644 code/__init__.py create mode 100644 code/local/__init__.py create mode 100644 code/local/maths.py create mode 100644 code/local/misc.py create mode 100644 code/local/system.py create mode 100644 code/local/typing.py create mode 100644 code/main.py create mode 100644 code/search/__init__.py create mode 100644 code/search/exports.py create mode 100644 code/search/methods.py diff --git a/code/__init__.py b/code/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/local/__init__.py b/code/local/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/local/maths.py b/code/local/maths.py new file mode 100644 index 0000000..9860590 --- /dev/null +++ b/code/local/maths.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import math; +import random; diff --git a/code/local/misc.py b/code/local/misc.py new file mode 100644 index 0000000..1cd2a32 --- /dev/null +++ b/code/local/misc.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import re; +from textwrap import dedent; diff --git a/code/local/system.py b/code/local/system.py new file mode 100644 index 0000000..a1c4947 --- /dev/null +++ b/code/local/system.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import os; +import sys; + +import pathlib; +import platform; +import shutil; +import subprocess; diff --git a/code/local/typing.py b/code/local/typing.py new file mode 100644 index 0000000..6dfe35d --- /dev/null +++ b/code/local/typing.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from types import TracebackType; + +from typing import Any; +from typing import Callable; +from typing import Dict; +from typing import Generator; +from typing import Generic; +from typing import List; +from typing import Tuple; +from typing import Type; +from typing import TypeVar; +from typing import Union; diff --git a/code/main.py b/code/main.py new file mode 100644 index 0000000..48fa7ec --- /dev/null +++ b/code/main.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +import os; +import sys; + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))); + +from code.search.exports import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# GLOBAL VARIABLES/CONSTANTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# MAIN PROCESS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +def main(): + goThroughCases(); + return; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# SECONDARY PROCESSES +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +def goThroughCases(): + ## Hier Fälle einfügen: + ## Case 1: + L = [1,3,5,7,11,13,17,19,23]; + u = 0; + v = len(L) - 1; + x = 13; + p = AlgoInterpol(L, u, v, x); + print('Ausführung des Interplationsalgorithmus:', p, L[p] if p >= 0 else None); + return; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXECUTE CODE +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +if __name__ == '__main__': + main(); diff --git a/code/search/__init__.py b/code/search/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/search/exports.py b/code/search/exports.py new file mode 100644 index 0000000..92caa27 --- /dev/null +++ b/code/search/exports.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from code.search.methods import AlgoInterpol; diff --git a/code/search/methods.py b/code/search/methods.py new file mode 100644 index 0000000..8989f42 --- /dev/null +++ b/code/search/methods.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from local.maths import *; +from local.typing import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# GLOBAL VARIABLES/CONSTANTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ALGORITHM +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +def AlgoInterpol(L: List[int], u: int, v: int, x: int) -> int: + if not(L[u] <= x and x <= L[v]): + print('out of bounds!') + return -1; + p = getSuchposition(L, u, v, x); + print('Interpolatiert von u={u}, v={v} -> p = {p}.'.format(u=u, v=v, p=p)); + if L[p] == x: + print('gefunden!'); + return p; + elif x > L[p]: + print('x > L[p]'); + return AlgoInterpol(L, p+1, v, x); + else: + print('x < L[p]'); + return AlgoInterpol(L, u, p-1, x); + +def getSuchposition(L: List[int], u: int, v: int, x: int) -> int: + r = (x - L[u])/(L[v]-L[u]); + p = math.floor(u + r*(v-u)) + return p;