diff --git a/algorithmen/shakersort.py b/algorithmen/shakersort.py new file mode 100644 index 0000000..ee38b2e --- /dev/null +++ b/algorithmen/shakersort.py @@ -0,0 +1,31 @@ +l = [12,124,1,31,51,4563,76,43,532,7,98,786,63,68,2,15,764,345,2,7,85] +l2 = [1235,999,432,123, 12, 5, 70] + +def shakersort(unsorted): + start = 0 + end = len(unsorted) - 1 # last possible index of list + exchanged = True + while exchanged and (end >= start): + exchanged = False + # Durchlauf vorwärts + for i in range(start, end, 1): + if unsorted[i] > unsorted[i + 1]: + # Vertausche! + unsorted[i], unsorted[i + 1] = unsorted[i + 1], unsorted[i] + exchanged = True + print(unsorted) + + # Durchlauf rückwärts + for j in range(end, start, -1): + if unsorted[j] < unsorted[j - 1]: + # Vertausche! + unsorted[j - 1], unsorted[j] = unsorted[j], unsorted[j - 1] + exchanged = True + print(unsorted) + + end = end - 1 + start = start + 1 + +print(str(l2) + " # unsortiert") +shakersort(l2) + diff --git a/automata/recog.py b/automata/recog.py new file mode 100644 index 0000000..862271d --- /dev/null +++ b/automata/recog.py @@ -0,0 +1,6 @@ +userin=input("Kennwort eingeben: ") + +if userin=="abc": + print("Passwort akzeptiert.") +else: + print("Authentifizierung fehlgeschlagen.") diff --git a/automata/simple_automaton.py b/automata/simple_automaton.py new file mode 100644 index 0000000..b62ef7a --- /dev/null +++ b/automata/simple_automaton.py @@ -0,0 +1,37 @@ + +states={0:"z1",1:"z2",2:"f"} +active=True +activestate=0 +intext="" + +print("Alphabet: a, b .") +print("Im Endzustand beendet '.'") + +while active: + + print("Zustand: " +states.get(activestate)) + userin = input("Eingabe: ") + + if activestate==0: + if userin == "a": + activestate=1 + intext=intext+userin + else: + pass + elif activestate==1: + if userin == "b": + activestate=2 + intext=intext+userin + else: + pass + elif activestate==2: + if userin == "a": + activestate=1 + intext=intext+userin + elif userin == ".": + intext=intext+userin + active=False + else: + pass + +print("Eingabe " + intext + " akzeptiert.")