master > master: code go - interactive mode eingerichtet
This commit is contained in:
@@ -8,15 +8,14 @@ import (
|
||||
"ads/internal/core/logging"
|
||||
"ads/internal/menus"
|
||||
"ads/internal/setup"
|
||||
"reflect"
|
||||
|
||||
// algorithm_search_binary "ads/internal/algorithms/search/binary"
|
||||
// algorithm_search_interpol "ads/internal/algorithms/search/interpol"
|
||||
// algorithm_search_ith_element "ads/internal/algorithms/search/ith_element"
|
||||
// algorithm_search_jump "ads/internal/algorithms/search/jump"
|
||||
// algorithm_search_poison "ads/internal/algorithms/search/poison"
|
||||
algorithm_search_binary "ads/internal/algorithms/search/binary"
|
||||
algorithm_search_interpol "ads/internal/algorithms/search/interpol"
|
||||
algorithm_search_ith_element "ads/internal/algorithms/search/ith_element"
|
||||
algorithm_search_jump "ads/internal/algorithms/search/jump"
|
||||
algorithm_search_poison "ads/internal/algorithms/search/poison"
|
||||
algorithm_search_sequential "ads/internal/algorithms/search/sequential"
|
||||
// algorithm_sum_maxsubsum "ads/internal/algorithms/sum/maxsubsum"
|
||||
algorithm_sum_maxsubsum "ads/internal/algorithms/sum/maxsubsum"
|
||||
)
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
@@ -43,6 +42,7 @@ var menuMain = menus.Menu{
|
||||
},
|
||||
Options: []menus.MenuOption{
|
||||
{Label: "Version des Programms anzeigen", Action: actionShowVersion},
|
||||
{Label: "Programm auf config Datei ausführen.", Action: actionRunOnConfig},
|
||||
{Label: "Suchalgorithmen", Submenu: &menuSearchAlgorithms},
|
||||
{Label: "Summenalgorithmen", Submenu: &menuSumAlgorithms},
|
||||
},
|
||||
@@ -56,14 +56,14 @@ var menuSearchAlgorithms = menus.Menu{
|
||||
"Algorithmus wählen",
|
||||
},
|
||||
Options: []menus.MenuOption{
|
||||
{Label: "Binärsuchalgorithmus"},
|
||||
{Label: "Interpolationsalgorithmus"},
|
||||
{Label: "Suche i. kleinstes Element"},
|
||||
{Label: "Suche i. kleinstes Element", SubLabel: "D & C"},
|
||||
{Label: "Sprungsuche", SubLabel: "linear"},
|
||||
{Label: "Sprungsuche", SubLabel: "exponentiell"},
|
||||
{Label: "Giftsuche"},
|
||||
{Label: "Giftsuche", SubLabel: "optimiert"},
|
||||
{Label: "Binärsuchalgorithmus", Action: actionAlgorithmSearchBinary},
|
||||
{Label: "Interpolationsalgorithmus", Action: actionAlgorithmSearchInterpolation},
|
||||
{Label: "Suche i. kleinstes Element", Action: actionAlgorithmSearchIthElement},
|
||||
{Label: "Suche i. kleinstes Element", SubLabel: "D & C", Action: actionAlgorithmSearchIthElementDc},
|
||||
{Label: "Sprungsuche", SubLabel: "linear", Action: actionAlgorithmSearchJump},
|
||||
{Label: "Sprungsuche", SubLabel: "exponentiell", Action: actionAlgorithmSearchJumpExp},
|
||||
{Label: "Giftsuche", Action: actionAlgorithmSearchPoison},
|
||||
{Label: "Giftsuche", SubLabel: "optimiert", Action: actionAlgorithmSearchPoisonFast},
|
||||
{Label: "Sequentiellsuchalgorithmus", Action: actionAlgorithmSearchSequential},
|
||||
},
|
||||
DefaultOption: -1,
|
||||
@@ -76,8 +76,8 @@ var menuSumAlgorithms = menus.Menu{
|
||||
"Algorithmus wählen",
|
||||
},
|
||||
Options: []menus.MenuOption{
|
||||
{Label: "Maximale Teilsumme", SubLabel: "brute force"},
|
||||
{Label: "Maximale Teilsumme", SubLabel: "D & C"},
|
||||
{Label: "Maximale Teilsumme", SubLabel: "brute force", Action: actionAlgorithmSumMaxsub},
|
||||
{Label: "Maximale Teilsumme", SubLabel: "D & C", Action: actionAlgorithmSumMaxsubDc},
|
||||
},
|
||||
DefaultOption: -1,
|
||||
}
|
||||
@@ -86,23 +86,259 @@ var menuSumAlgorithms = menus.Menu{
|
||||
* ACTIONS - basic
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func actionShowVersion() error {
|
||||
func actionShowVersion() (bool, error) {
|
||||
logging.LogInfo("Version des Programms")
|
||||
Version()
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* ACTIONS - Algorithmen
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
// TODO
|
||||
func actionAlgorithmSearchSequential() error {
|
||||
input_L := []int{45, 67}
|
||||
input_x := 6
|
||||
menus.PromptValue("L", "Liste von Integers", "z.B. \033[1m5 73 42\033[0m", reflect.TypeOf([]int{}))
|
||||
func actionRunOnConfig() (bool, error) {
|
||||
path, cancel, err := logging.Prompt("Pfad zur Configdatei bitte eingeben:")
|
||||
if cancel {
|
||||
err = nil
|
||||
} else if err == nil {
|
||||
err = RunNonInteractive(path)
|
||||
}
|
||||
return cancel, err
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchBinary() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{
|
||||
"muss aufsteigend sortiert sein",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_x, cancel, err := PromptInputInteger("x", "Suchwert", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_binary.FancyBinarySearch(input_L, input_x)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchInterpolation() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{
|
||||
"muss aufsteigend sortiert sein",
|
||||
"sollte (idealerweise) nicht uniform verteilt sein",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_x, cancel, err := PromptInputInteger("x", "Suchwert", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_interpol.FancyInterpolationSearch(input_L, input_x, 0, len(input_L)-1)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchIthElement() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_i, cancel, err := PromptInputInteger("i", "Suchindex in sortierter Liste", []string{
|
||||
"sollte zw. 1 und len(L) liegen",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_ith_element.FancyFindIthSmallest(input_L, input_i)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchIthElementDc() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_i, cancel, err := PromptInputInteger("i", "Suchindex in sortierter Liste", []string{
|
||||
"sollte zw. 1 und len(L) liegen",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_ith_element.FancyFindIthSmallestDC(input_L, input_i)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchJump() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{
|
||||
"muss aufsteigend sortiert sein",
|
||||
"sollte (idealerweise) nicht uniform verteilt sein",
|
||||
"sollte (idealerweise) keine Duplikate enthalten",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_x, cancel, err := PromptInputInteger("x", "Suchwert", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_m, cancel, err := PromptInputInteger("m", "Sprunggröße", []string{
|
||||
"sollte >= 2 sein",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_jump.FancyJumpSearchLinear(input_L, input_x, input_m)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchJumpExp() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{
|
||||
"muss aufsteigend sortiert sein",
|
||||
"sollte (idealerweise) nicht uniform verteilt sein",
|
||||
"sollte (idealerweise) keine Duplikate enthalten",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_x, cancel, err := PromptInputInteger("x", "Suchwert", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_jump.FancyJumpSearchExponentiell(input_L, input_x)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchPoison() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{
|
||||
"muss genau eine 1 enthalten",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_poison.FancyFindPoison(input_L)
|
||||
logging.Prompt("hallo")
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchPoisonFast() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfZeroOnes("L", "Liste von Getränken", []string{
|
||||
"muss genau eine 1 enthalten",
|
||||
})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_poison.FancyFindPoisonFast(input_L)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSearchSequential() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
input_x, cancel, err := PromptInputInteger("x", "Suchwert", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_search_sequential.FancySequentialSearch(input_L, input_x)
|
||||
setup.DisplayEndOfCase()
|
||||
return nil
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSumMaxsub() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_sum_maxsubsum.FancyMaxSubSum(input_L)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func actionAlgorithmSumMaxsubDc() (bool, error) {
|
||||
input_L, cancel, err := PromptInputListOfInt("L", "Liste von Werten", []string{})
|
||||
if cancel || err != nil {
|
||||
return cancel, err
|
||||
}
|
||||
setup.DisplayStartOfCaseBlank()
|
||||
algorithm_sum_maxsubsum.FancyMaxSubSumDC(input_L)
|
||||
setup.DisplayEndOfCase()
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* CUSTOM PROMPTS für besondere Inputs
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func PromptInputInteger(name string, descr string, requirements []string) (int, bool, error) {
|
||||
type responseType struct {
|
||||
Response int `yaml:"response"`
|
||||
}
|
||||
var response = responseType{}
|
||||
var query = menus.PromptValueQuery{
|
||||
Description: descr,
|
||||
Name: name,
|
||||
Type: "Integer",
|
||||
Requirements: &requirements,
|
||||
Response: &response,
|
||||
}
|
||||
cancel, err := query.Prompt()
|
||||
return response.Response, cancel, err
|
||||
}
|
||||
|
||||
func PromptInputListOfInt(name string, descr string, requirements []string) ([]int, bool, error) {
|
||||
type responseType struct {
|
||||
Response []int `yaml:"response"`
|
||||
}
|
||||
var response = responseType{}
|
||||
var query = menus.PromptValueQuery{
|
||||
Description: descr,
|
||||
Name: name,
|
||||
Type: "Integerliste",
|
||||
ValidExamples: &[]string{
|
||||
"[1, 2, 7, 8, 5]",
|
||||
"[1000, 0, 4]",
|
||||
},
|
||||
Requirements: &requirements,
|
||||
Response: &response,
|
||||
}
|
||||
cancel, err := query.Prompt()
|
||||
return response.Response, cancel, err
|
||||
}
|
||||
|
||||
func PromptInputListOfZeroOnes(name string, descr string, requirements []string) ([]int, bool, error) {
|
||||
type responseType struct {
|
||||
Response []int `yaml:"response"`
|
||||
}
|
||||
var response = responseType{}
|
||||
var query = menus.PromptValueQuery{
|
||||
Description: descr,
|
||||
Name: name,
|
||||
Type: "Liste von 0er und 1er",
|
||||
ValidExamples: &[]string{
|
||||
"[0, 0, 0, 1, 0]",
|
||||
"[1, 0, 1, 1]",
|
||||
},
|
||||
Requirements: &requirements,
|
||||
Response: &response,
|
||||
}
|
||||
cancel, err := query.Prompt()
|
||||
return response.Response, cancel, err
|
||||
}
|
||||
|
||||
@@ -24,12 +24,10 @@ import (
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
// Liest Config Datei ein und führt Algorithmen auf Fälle durch
|
||||
func RunNoninteractive(path string) error {
|
||||
func RunNonInteractive(path string) error {
|
||||
var err error
|
||||
var err_case error
|
||||
|
||||
logging.LogPlain(setup.Logo())
|
||||
|
||||
// extrahiere user config
|
||||
config := setup.NewUserConfig()
|
||||
err = setup.GetUserConfig(path, &config)
|
||||
@@ -37,6 +35,8 @@ func RunNoninteractive(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogPlain(setup.Logo())
|
||||
|
||||
// Fälle extrahieren
|
||||
cases := []types.UserConfigCase{}
|
||||
if config.Parts != nil && config.Parts.Cases != nil {
|
||||
|
||||
Reference in New Issue
Block a user