diff options
-rwxr-xr-x | .classpath | 6 | ||||
-rw-r--r-- | .gitignore | 171 | ||||
-rwxr-xr-x | .project | 17 | ||||
-rwxr-xr-x | src/com/encrox/automaten/Core.java | 262 | ||||
-rwxr-xr-x | src/com/encrox/automaten/Schlange.java | 56 | ||||
-rwxr-xr-x | src/com/encrox/automaten/Stapel.java | 54 |
6 files changed, 566 insertions, 0 deletions
diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..d171cd4 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d02df8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,171 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/eclipse,java,windows,linux,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java,windows,linux,macos + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/eclipse,java,windows,linux,macos diff --git a/.project b/.project new file mode 100755 index 0000000..e4b0df8 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Automaten</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/src/com/encrox/automaten/Core.java b/src/com/encrox/automaten/Core.java new file mode 100755 index 0000000..3ec994f --- /dev/null +++ b/src/com/encrox/automaten/Core.java @@ -0,0 +1,262 @@ +package com.encrox.automaten;
+
+public class Core {
+
+ public static void main(String args[]) {
+ System.out.println(isOkNormal("z"));
+ System.out.println(isOk("z"));
+ }
+
+ public static boolean isOkNormal(String str) {
+ boolean out = false;
+ char current;
+ Schlange schlange = new Schlange();
+ for(int i = 0, len = str.length(); i<len; i++) {
+ schlange.anhaengen(str.charAt(i));
+ }
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'e') {
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ } else if(current == 'k') {
+ out = false;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ } else if(current == '0') {
+ out = false;
+ } else if(current == 'e') {
+ out = false;
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'e') {
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ } else if(current == 'k') {
+ out = false;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ } else if(current == '0') {
+ out = false;
+ } else if(current == 'e') {
+ out = false;
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return out;
+ }
+
+ public static boolean isOk(String str) {
+ Schlange schlange = new Schlange();
+ for(int i = 0, len = str.length(); i<len; i++) {
+ schlange.anhaengen(str.charAt(i));
+ }
+ char c = (char)schlange.entnehmen();
+ if(c == '-') {
+ return a(schlange);
+ } else if(c == 'z') {
+ return b(schlange);
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean a(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ if((char)schlange.entnehmen() == 'z') {
+ return b(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean b(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == 'e') {
+ return e(schlange);
+ } else if(c == 'k') {
+ return c(schlange);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean c(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == '0') {
+ return c(schlange);
+ } else if(c == 'z') {
+ return f(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean f(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == 'z') {
+ return f(schlange);
+ } else if(c == '0') {
+ return c(schlange);
+ } else if(c == 'e') {
+ return e(schlange);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean e(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == 'z') {
+ return h(schlange);
+ } else if(c == '-') {
+ return g(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean g(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ if((char)schlange.entnehmen() == 'z') {
+ return h(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean h(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == '0' || c == 'z') {
+ return h(schlange);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/encrox/automaten/Schlange.java b/src/com/encrox/automaten/Schlange.java new file mode 100755 index 0000000..c5b7f65 --- /dev/null +++ b/src/com/encrox/automaten/Schlange.java @@ -0,0 +1,56 @@ +package com.encrox.automaten; + +public class Schlange { + + Schlange next; + Object inhalt; + + public Schlange(){ + + } + + private int zaehlen(){ + if (next == null) return 0; + else return 1+next.zaehlen(); + } + + public boolean istLeer(){ + if (zaehlen()==0) return true; + else return false; + } + + public void anhaengen(Object i){ + if (next == null){ + Schlange element = new Schlange(); + element.inhalt=i; + next = element; + } + else next.anhaengen(i); + } + + public Object inhaltGeben(){ + if (next != null) return next.inhalt; + else return null; + } + + public Object entnehmen(){ + if (next != null){ + Object i = next.inhalt; + next = next.next; + return i; + } + return null; + } + + public String ausgeben(){ + String s=""; + if (inhalt != null){ + s = s+inhalt.toString()+"\n"; + } + if (next != null){ + s = s + next.ausgeben(); + } + return s; + } + +} diff --git a/src/com/encrox/automaten/Stapel.java b/src/com/encrox/automaten/Stapel.java new file mode 100755 index 0000000..a4c5ee9 --- /dev/null +++ b/src/com/encrox/automaten/Stapel.java @@ -0,0 +1,54 @@ + +package com.encrox.automaten; + +public class Stapel { + + Object inhalt; + Stapel next; + + private int zaehlen(){ + if (next == null) return 0; + else return 1+next.zaehlen(); + } + + public Stapel(){ + } + + public boolean istLeer(){ + if (zaehlen()==0) return true; + else return false; + } + + public void ablegen(Object i){ + Stapel element = new Stapel(); + element.inhalt = i; + element.next = next; + next = element; + } + + public Object inhaltGeben(){ + if (next != null) return next.inhalt; + else return null; + } + + public Object entnehmen(){ + if (next != null){ + Object i = next.inhalt; + next = next.next; + return i; + } + return null; + } + + public String ausgeben(){ + String s=""; + if (inhalt != null){ + s = s+inhalt.toString()+"\n"; + } + if (next != null){ + s = s + next.ausgeben(); + } + return s; + } + +} |