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.
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)
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.
Possible: bfhjklpquwxyz Impossible: acdegimnorstv
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+"')");
}
}
}
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.
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