master > master: code - hinzugefügt
This commit is contained in:
0
code/search/__init__.py
Normal file
0
code/search/__init__.py
Normal file
8
code/search/exports.py
Normal file
8
code/search/exports.py
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from code.search.methods import AlgoInterpol;
|
||||
40
code/search/methods.py
Normal file
40
code/search/methods.py
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user