Compare commits
No commits in common. "aaa0b7a12430a9d1a4e0d946610402d5fa959462" and "f6401f0dfc286a9fbd7210ecbe30c95abee9cff9" have entirely different histories.
aaa0b7a124
...
f6401f0dfc
|
@ -126,4 +126,3 @@
|
||||||
- 58
|
- 58
|
||||||
- name: POLLARD-RHO
|
- name: POLLARD-RHO
|
||||||
number: 534767
|
number: 534767
|
||||||
x-init: 5
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.3.0
|
0.2.0
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
# CommandEuklid
|
|
||||||
## Properties
|
|
||||||
|
|
||||||
Name | Type | Description | Notes
|
|
||||||
------------ | ------------- | ------------- | -------------
|
|
||||||
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
|
||||||
**numbers** | [**List**](integer.md) | | [default to null]
|
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
# CommandPollard
|
|
||||||
## Properties
|
|
||||||
|
|
||||||
Name | Type | Description | Notes
|
|
||||||
------------ | ------------- | ------------- | -------------
|
|
||||||
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
|
||||||
**number** | [**Integer**](integer.md) | | [default to null]
|
|
||||||
**xMinusinit** | [**Integer**](integer.md) | | [optional] [default to 2]
|
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
|
||||||
**algorithm** | [**EnumRucksackAlgorithm**](EnumRucksackAlgorithm.md) | | [default to null]
|
**algorithm** | [**EnumRucksackAlgorithm**](EnumRucksackAlgorithm.md) | | [default to null]
|
||||||
**allowMinusfractional** | [**Boolean**](boolean.md) | | [optional] [default to false]
|
**allowMinusfractional** | [**Boolean**](boolean.md) | | [optional] [default to false]
|
||||||
**maxMinuscost** | [**BigDecimal**](number.md) | Upper bound for total cost of rucksack. | [default to null]
|
**maxMinuscost** | [**BigDecimal**](number.md) | Upper bound for total cost of rucksack. | [default to null]
|
||||||
|
|
|
@ -13,9 +13,7 @@ Class | Method | HTTP request | Description
|
||||||
## Documentation for Models
|
## Documentation for Models
|
||||||
|
|
||||||
- [Command](.//Models/Command.md)
|
- [Command](.//Models/Command.md)
|
||||||
- [CommandEuklid](.//Models/CommandEuklid.md)
|
|
||||||
- [CommandHirschberg](.//Models/CommandHirschberg.md)
|
- [CommandHirschberg](.//Models/CommandHirschberg.md)
|
||||||
- [CommandPollard](.//Models/CommandPollard.md)
|
|
||||||
- [CommandRucksack](.//Models/CommandRucksack.md)
|
- [CommandRucksack](.//Models/CommandRucksack.md)
|
||||||
- [CommandTarjan](.//Models/CommandTarjan.md)
|
- [CommandTarjan](.//Models/CommandTarjan.md)
|
||||||
- [CommandTsp](.//Models/CommandTsp.md)
|
- [CommandTsp](.//Models/CommandTsp.md)
|
||||||
|
|
|
@ -9,8 +9,6 @@ Name | Type | Description | Notes
|
||||||
**tsp** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
**tsp** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
**hirschberg** | [**AppOptions_hirschberg**](AppOptions_hirschberg.md) | | [default to null]
|
**hirschberg** | [**AppOptions_hirschberg**](AppOptions_hirschberg.md) | | [default to null]
|
||||||
**rucksack** | [**AppOptions_rucksack**](AppOptions_rucksack.md) | | [default to null]
|
**rucksack** | [**AppOptions_rucksack**](AppOptions_rucksack.md) | | [default to null]
|
||||||
**euklid** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
|
||||||
**pollardMinusrho** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: 0.3.0
|
version: 0.2.0
|
||||||
title: Schemata for command instructions
|
title: Schemata for command instructions
|
||||||
servers:
|
servers:
|
||||||
- url: "."
|
- url: "."
|
||||||
|
@ -185,10 +185,6 @@ components:
|
||||||
number:
|
number:
|
||||||
type: integer
|
type: integer
|
||||||
exclusiveMinimum: 0
|
exclusiveMinimum: 0
|
||||||
x-init:
|
|
||||||
type: integer
|
|
||||||
default: 2
|
|
||||||
minimum: 2
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# Enum Algorithm Names
|
# Enum Algorithm Names
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: 0.3.0
|
version: 0.2.0
|
||||||
title: Schemata for config models
|
title: Schemata for config models
|
||||||
servers:
|
servers:
|
||||||
- url: "."
|
- url: "."
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "uni-leipzig-ads-2-2022"
|
name = "uni-leipzig-ads-2-2022"
|
||||||
version = "0.3.0"
|
version = "0.2.0"
|
||||||
description = "Zusatzcode, um Algorithmen und Datenstrukturen im Kurs ADS2 zu demonstrieren."
|
description = "Zusatzcode, um Algorithmen und Datenstrukturen im Kurs ADS2 zu demonstrieren."
|
||||||
authors = [ "Raj Dahya" ]
|
authors = [ "Raj Dahya" ]
|
||||||
maintainers = [ "raj_mathe" ]
|
maintainers = [ "raj_mathe" ]
|
||||||
|
|
|
@ -94,4 +94,5 @@ def euklidean_algorithm(
|
||||||
print(f'a=\x1b[1m{step.a}\x1b[0m; b=\x1b[1m{step.b}\x1b[0m; d = \x1b[1m{step.gcd}\x1b[0m = {expr}.');
|
print(f'a=\x1b[1m{step.a}\x1b[0m; b=\x1b[1m{step.b}\x1b[0m; d = \x1b[1m{step.gcd}\x1b[0m = {expr}.');
|
||||||
print('');
|
print('');
|
||||||
|
|
||||||
|
|
||||||
return d, coeff_a, coeff_b;
|
return d, coeff_a, coeff_b;
|
||||||
|
|
|
@ -10,8 +10,8 @@ from src.thirdparty.maths import *;
|
||||||
|
|
||||||
from models.generated.config import *;
|
from models.generated.config import *;
|
||||||
from src.core.utils import *;
|
from src.core.utils import *;
|
||||||
from src.models.pollard_rho import *;
|
# from src.models.pollard_rho import *;
|
||||||
from src.algorithms.pollard_rho.display import *;
|
from src.algorithms.euklid.display import *;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# EXPORTS
|
# EXPORTS
|
||||||
|
@ -27,48 +27,6 @@ __all__ = [
|
||||||
|
|
||||||
def pollard_rho_algorithm(
|
def pollard_rho_algorithm(
|
||||||
n: int,
|
n: int,
|
||||||
x_init: int = 2,
|
|
||||||
verbose: bool = False,
|
verbose: bool = False,
|
||||||
):
|
):
|
||||||
d = 1;
|
return;
|
||||||
x = y = x_init;
|
|
||||||
steps = [];
|
|
||||||
steps.append(Step(x=x, y=y));
|
|
||||||
success = False;
|
|
||||||
f = lambda _: fct(_, n=n);
|
|
||||||
while True:
|
|
||||||
x = f(x);
|
|
||||||
y = f(f(y));
|
|
||||||
d = math.gcd(abs(x-y), n);
|
|
||||||
steps.append(Step(x=x, y=y, d=d));
|
|
||||||
if d == 1:
|
|
||||||
continue;
|
|
||||||
elif d < n:
|
|
||||||
success = True;
|
|
||||||
break;
|
|
||||||
else:
|
|
||||||
success = False;
|
|
||||||
break;
|
|
||||||
|
|
||||||
if verbose:
|
|
||||||
repr = display_table(steps=steps);
|
|
||||||
print('');
|
|
||||||
print('\x1b[1mEuklidescher Algorithmus\x1b[0m');
|
|
||||||
print('');
|
|
||||||
print(repr);
|
|
||||||
print('');
|
|
||||||
if success:
|
|
||||||
print('\x1b[1mBerechneter Faktor:\x1b[0m');
|
|
||||||
print('');
|
|
||||||
print(f'd = \x1b[1m{d}\x1b[0m.');
|
|
||||||
else:
|
|
||||||
print('\x1b[91mKein (Prim)faktor erkannt!\x1b[0m');
|
|
||||||
print('');
|
|
||||||
return d;
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# AUXILIARY METHOD function for Pollard's rho
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
def fct(x: int, n: int) -> int:
|
|
||||||
return (x**2 - 1) % n;
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# IMPORTS
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
from src.thirdparty.code import *;
|
|
||||||
from src.thirdparty.maths import *;
|
|
||||||
from src.thirdparty.types import *;
|
|
||||||
|
|
||||||
from src.models.pollard_rho import *;
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# EXPORTS
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
'display_table',
|
|
||||||
];
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# METHOD display table
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
def display_table(steps: List[Step]) -> str:
|
|
||||||
table = pd.DataFrame({
|
|
||||||
'i': [i for i in range(len(steps))],
|
|
||||||
'x': [step.x for step in steps],
|
|
||||||
'y': [step.y for step in steps],
|
|
||||||
'd': [step.d or '-' for step in steps],
|
|
||||||
}) \
|
|
||||||
.reset_index(drop=True);
|
|
||||||
# benutze pandas-Dataframe + tabulate, um schöner darzustellen:
|
|
||||||
repr = tabulate(
|
|
||||||
table,
|
|
||||||
headers=['i', 'x[i]', 'y[i] = x[2i]', 'gcd(|x - y|,n)'],
|
|
||||||
showindex=False,
|
|
||||||
colalign=('right', 'right', 'right', 'center'),
|
|
||||||
tablefmt='simple',
|
|
||||||
);
|
|
||||||
return repr;
|
|
|
@ -28,7 +28,6 @@ __all__ = [
|
||||||
def endpoint_pollard_rho(command: CommandPollard) -> Result[CallResult, CallError]:
|
def endpoint_pollard_rho(command: CommandPollard) -> Result[CallResult, CallError]:
|
||||||
result = pollard_rho_algorithm(
|
result = pollard_rho_algorithm(
|
||||||
n = command.number,
|
n = command.number,
|
||||||
x_init = command.x_init,
|
|
||||||
verbose = config.OPTIONS.tsp.verbose,
|
verbose = config.OPTIONS.tsp.verbose,
|
||||||
);
|
);
|
||||||
return Ok(CallResult(action_taken=True, message=result));
|
return Ok(CallResult(action_taken=True, message=result));
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# IMPORTS
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
from src.models.pollard_rho.logging import *;
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# EXPORTS
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
'Step',
|
|
||||||
];
|
|
|
@ -1,26 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# IMPORTS
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
from src.thirdparty.types import *;
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# EXPORTS
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
'Step',
|
|
||||||
];
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# CLASS Step
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Step():
|
|
||||||
x: int = field();
|
|
||||||
y: int = field();
|
|
||||||
d: Optional[int] = field(default=None);
|
|
Loading…
Reference in New Issue