[Java] One type of alphabet prohibited FizzBuzz with binding [Binding]

Overview

In Java, I verified which alphabet can be written by prohibiting one alphabet (writing without using one of a to z). Just play. Previous article FizzBuzz version.

Previously, it was easy to avoid string constants ("Hello, world"), so it was mainly avoided by "class declaration", "main declaration", and "output statement". Since all of them exist this time as well, the alphabet \ (acdegimnorstv ) that was not tied before cannot be tied. So, I will verify whether FizzBuzz can also bind "bfhjklpquwxyz" that was tied last time.

rule

  1. java10
  2. Compile with javac, execute with java, no options (or rather, write and execute in Eclipse)
  3. Output FizzBuzz to standard output
  4. One line for each number
  5. The characters are "Fizz" "Buzz" "FizzBuzz"
  6. The number of times of FizzBuzzz is 20 times at runtime, but in implementation it can be up to half </ font> of the maximum value of int type.
  7. Embedding does not solve loops and conditional branches
  8. Extra standard output and error output are prohibited (line breaks are OK)
  9. Prohibition of using only one type of alphabet
  10. Case insensitive
  11. Prohibit external files (only Java standard library is possible)
  12. Unicode escape prohibited

The reason for the 4th binding was that I thought that the upper limit of FizzBuzz could be lowered by using bytes etc. to avoid the alphabet, so I thought that I could make the range of general numeric type int possible. (That is, long is OK)

  • Added on 2018/12/19 Comment told me that it does not end with overflow at the maximum INT type. It can be solved by shifting the index, but it is different from the Wikipedia code and it is not the essence of binding, so I changed it to half of the INT type maximum value and cheated.

The reason for binding No. 5 is that if there is embedding, if you embed all the output as it is without using an extreme loop, the content will be no different from the previous Hello, world. It is difficult to judge how much is embedded, but it is a self-judgment. If you don't like the judgment, write an article that you tried based on your own judgment criteria.

Execution example


1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

For the 10th binding, see Previous article.

Conclusion

Possible: bfhjklpquwxyz Impossible: acdegimnorstv

  • No difference from the last time

Details

I'm writing a code that is roughly tied in alphabetical order. I haven't explained much about the technique I used last time. hjkqwx First of all, I wrote FizzBuzz normally. There are many ways to do it, so I just rewrote the python code in Wikipedia to java. As in the example, variable names are written in Japanese so as not to use the alphabet.

Fizz buzz.java


class fizz buzz{
	public static void main(String[]argument) {
		for (int number=1;number<= 20;number++) {
			if (number% 15 == 0)
				System.out.println("FizzBuzz");
			else if (number% 3 == 0)
				System.out.println("Fizz");
			else if (number% 5 == 0)
				System.out.println("Buzz");
			else
				System.out.println(number);
		}
	}
}

bpz First, I erased it by writing the character string in char type and waking it up in format. This will erase z. Next, make it an interface and delete the public of the main method. This makes b disappear. It didn't disappear more than I expected.

Fizz buzz.java


interface fizz buzz{
	static void main(String[]argument) {
		for (int number=1;number<= 20;number++) {
			if (number% 15 == 0)
				System.out.format("%c%c%c%c%c%c%c%c%c",70,105,122,122,66,117,122,122,10);
			else if (number% 3 == 0)
				System.out.format("%c%c%c%c%c",70,105,122,122,10);
			else if (number% 5 == 0)
				System.out.format("%c%c%c%c%c",66,117,122,122,10);
			else
				System.out.format("%d%c",number,10);
		}
	}
}

f I use it for for, if and format. I changed the format to print and replaced it with a char array. for is while. if used switch like an if statement. I'm writing an increment because I'm using continue instead of else. Change the initial value separately

Fizz buzz.java


class fizz buzz{
	public static void main(String[]argument) {
int number=0;
		while (number< 20) {
number++;
			switch(number% 15){
			case 0:
				System.out.print(new char[] {70,105,122,122,66,117,122,122,10});
				continue;
			}
			switch(number% 3){
			case 0:
				System.out.print(new char[] {70,105,122,122,10});
				continue;
			}
			switch(number% 5){
			case 0:
				System.out.print(new char[] {66,117,122,122,10});
				continue;
			}
			System.out.print(number+"\n");
		}
	}
}

l I used it with else and println. The one above is not using them, but I have used them in while, so I can change it to for. Since it is also used in public, change it to interface.

Fizz buzz.java


interface fizz buzz{
	static void main(String[]argument) {
		for(int number=1;number<= 20;number++) {
			switch(number% 15){
			case 0:
				System.out.print(new char[] {70,105,122,122,66,117,122,122,10});
				continue;
			}
			switch(number% 3){
			case 0:
				System.out.print(new char[] {70,105,122,122,10});
				continue;
			}
			switch(number% 5){
			case 0:
				System.out.print(new char[] {66,117,122,122,10});
				continue;
			}
			System.out.print(number+"\n");
		}
	}
}

uy How to replace s [y] stem.o [u] t with the same ScriptEngine as last time. Since it is also in B [u] zz, the character string is a char array.

Fizz buzz.java


import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
interface fizz buzz{
	static void main(String[]argument) throws Exception{
		ScriptEngineManager manager = new ScriptEngineManager();
		ScriptEngine engine = (ScriptEngine)manager.getClass()
				.getMethod("getEngineB"+(char)121+"Name", String.class).invoke(manager, "javascript");
		for (int number=1;number<= 20;number++) {
			if (number% 15 == 0)
				engine.eval("print('"+new String(new char[] {70,105,122,122,66,117,122,122})+"')");
			else if (number% 3 == 0)
				engine.eval("print('"+new String(new char[] {70,105,122,122})+"')");
			else if (number% 5 == 0)
				engine.eval("print('"+new String(new char[] {66,117,122,122})+"')");
			else
				engine.eval("print('"+number+"')");
		}
	}
}

Untied characters and reasons

acdgimnorstv Because static void main (String [] argument) is absolutely necessary.

e Like uy, it's in Syst [e] m.out, and it's also in Script [E] ngin [e]. Even if you try to get it from a character string, it is in g [e] tClass. Even if it isn't, it's an alphabet that is fairly easy to use, so it's usually caught.

At the end

From the above Possible: bfhjklpquwxyz Impossible: acdegimnorstv Will be. The result was the same as last time. It wasn't that interesting. After all, the declaration part of class or main should be ignored. I thought, but then I should do it with python.

Recommended Posts

[Java] One type of alphabet prohibited FizzBuzz with binding [Binding]
[Java] One type of alphabet prohibited With binding Hello, world! [Binding]
Initialization with an empty string to an instance of Java String type
Bokuga Kanga Etasaikyo's FizzBuzz (@Java) with 1 year of programmer experience
[Java] Correct comparison of String type
[Java] Implicit type cast (AOJ10-sum of numbers)
[Basic knowledge of Java] About type conversion
[Java] Comparison of String type character strings
Java Summary of frequently searched type conversions
[Java] How to convert one element of a String type array to an Int type
[Java] Explanation of Strategy pattern (with sample code)
[Java] Be careful of the key type of Map
[Java] Create a collection with only one element
Calculate the similarity score of strings with JAVA
Java Repository of Eclipse with Maven: Missing artifact ~
Java review ③ (Basic usage of arrays / reference type)