master > master: code - max teilsumme x 2 hinzugefügt

This commit is contained in:
RD
2021-10-24 19:33:08 +02:00
parent 2c94de5854
commit 64df98fcf3
9 changed files with 277 additions and 6 deletions

View File

@@ -9,3 +9,4 @@ from code.algorithms.search.sequential import SequentialSearch;
from code.algorithms.search.binary import BinarySearch;
from code.algorithms.search.interpol import InterpolationSearch;
from code.algorithms.search.jump import JumpSearchLinear;
from code.algorithms.search.selection import SelectionAlgorithm;

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# IMPORTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from local.maths import *;
from local.typing import *;
from code.core.log import *;
from code.algorithms.search.sequential import SequentialSearch;
from code.algorithms.methods import *;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# GLOBAL VARIABLES/CONSTANTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CHECKS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def preChecks(L: List[int], **_):
assert L == sorted(L), 'Ungültiger Input: L muss aufsteigend sortiert sein!';
assert L == list(sorted(set(L))), 'Ungültiger Input: L darf keine Duplikate enthalten!';
return;
def postChecks(L: List[int], x: int, index: int, **_):
value = L[index] if index >= 0 else None;
assert value == x, 'Der Algorithmus hat versagt.';
return;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ALGORITHM jump search
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@algorithmInfos(name='Auswahlproblem (i. Element)', outputnames='index', checks=True, metrics=True, preChecks=preChecks, postChecks=postChecks)
def SelectionAlgorithm(L: List[int], i: int) -> int:
'''
Inputs: L = Liste von Zahlen, i = Ordinalzahl
Outputs: Position des i. kleinste Element, x, in L, sonst 1. Beachte i=0 <==> Minimum.
'''
## TODO
return -1;