Talk:Sugueziume
Jump to navigation
Jump to search
Implementation
In Eclipse, using this Java implementation, while running the truth-machine, the loop seems to be too fast to see it print X's, but this can be fixed by changed System.out.print to System.out.println. It all comes down to your preference with this language, and whether it prints newlines is not standardized in Sugueziume's specification. Separate the code and input lines with "@END", and put it all into standard input.
import java.util.Scanner; import java.util.ArrayDeque; import java.util.Arrays; import java.io.File; import java.io.FileNotFoundException; public class Main { public static void main(String[] args) throws FileNotFoundException, Exception { Scanner in = new Scanner(System.in); String code = ""; String arg1, arg2, arg3, arg4, arg5, arg6; boolean shouldhalt = false; String str = ""; while (!str.equals("@END")) { str = in.nextLine(); if (str.matches("[A-Z, ]+")) code += str; else if (!str.equals("@END")) throw new Exception("Code should not contain characters other than capital English letters, spaces, and commas."); } ArrayDeque<String> storage = new ArrayDeque<>(); for (String s : code.split(",")) { storage.addLast(s); } String current = ""; while (!storage.isEmpty() && !shouldhalt) { current = storage.removeFirst(); for (int i = 0; i < current.length() && !shouldhalt; i++) { switch (current.charAt(i)) { case 'A': storage.removeFirst(); break; case 'B': storage.addLast(storage.removeFirst()); break; case 'C': arg1 = current.substring(i + 1); storage.addLast(arg1); continue; case 'D': arg1 = storage.removeFirst(); arg2 = storage.removeFirst(); arg3 = ""; for (int j = 0; j < Math.max(arg1.length(), arg2.length()); j++) { arg3 += j < arg1.length() ? arg1.charAt(j) : ' '; arg3 += j < arg2.length() ? arg2.charAt(j) : ' '; } storage.addLast(arg3); break; case 'E': arg1 = storage.removeFirst(); storage.addLast(arg1); storage.addLast(arg1); break; case 'F': arg1 = storage.removeFirst(); arg2 = storage.removeFirst(); arg3 = storage.removeFirst(); arg4 = storage.removeFirst(); arg5 = storage.removeFirst(); arg6 = storage.removeFirst(); storage.addLast(arg2); storage.addLast(arg3); storage.addLast(arg4); storage.addLast(arg5); storage.addLast(arg6); storage.addLast(arg1); break; case 'G': { arg1 = in.nextLine(); arg2 = ""; String[] arguments = arg1.split("[^A-Z, ]"); for (int j = 0; j < arguments.length; j++) arg2 += arguments[j]; storage.addLast(arg2); break; } case 'H': System.out.print(storage.removeFirst()); break; case 'I': arg1 = storage.removeFirst(); if (arg1.contains("X") && current.substring(0, i).contains("I")) i = current.lastIndexOf("I", i - 1); break; case 'J': arg1 = storage.removeFirst(); if (arg1.contains("X") && current.substring(i + 1, current.length()).contains("J")) i = current.indexOf("J", i); break; case 'K': arg1 = storage.removeFirst(); arg2 = storage.removeFirst(); arg3 = ""; for (int j = 0; j < Math.min(arg1.length(), arg2.length()); j++) if ("BDFHJLNPRTVXZ".contains("" + arg2.charAt(j))) arg3 += arg1.charAt(j); storage.addLast(arg3); break; case 'L': arg1 = storage.removeFirst(); arg2 = storage.removeFirst(); arg3 = storage.removeFirst(); storage.addLast((arg1.length() % 2 == 1) ? arg2 : arg3); break; case 'M': arg1 = storage.removeFirst(); arg2 = storage.removeFirst(); arg3 = storage.removeFirst(); arg4 = ""; for (int j = 0; j < Math.max(arg1.length(), Math.max(arg2.length(), arg3.length())); j++) { arg4 += j < arg1.length() ? arg1.charAt(j) : ' '; arg4 += j < arg2.length() ? arg2.charAt(j) : ' '; arg4 += j < arg3.length() ? arg3.charAt(j) : ' '; } storage.addLast(arg4); break; case 'N': { String[] arguments = new String[storage.removeFirst().length()]; String totalchars = ""; int maxlength = 0; for (int j = 0; j < arguments.length; j++) arguments[j] = storage.removeFirst(); for (int j = 0; j < arguments.length; j++) maxlength = Math.max(maxlength, arguments[j].length()); for (int j = 0; j < maxlength; j++) for (int k = 0; k < arguments.length; k++) totalchars += j < arguments[k].length() ? arguments[k].charAt(j) : ' '; storage.addLast(totalchars); break; } case 'O': shouldhalt = true; break; case 'P': arg1 = storage.removeFirst(); for (int j = 0; j < arg1.length(); j++) storage.addLast("" + arg1.charAt(j)); break; case 'Q': arg1 = storage.removeFirst(); for (int j = arg1.length() - 1; j >= 0; j--) storage.addLast("" + arg1.charAt(j)); break; case 'R': arg1 = storage.removeFirst(); arg2 = storage.removeFirst(); storage.addLast(arg2.replace(arg1.charAt(0), arg1.charAt(1))); break; } } } } }
BoundedBeans (talk) 23:10, 11 July 2022 (UTC)
- I mean you can modify the H case and change the print method. Guess I forgot to specify where the part to change was. BoundedBeans (talk) 23:10, 11 July 2022 (UTC)