Last active
August 29, 2015 14:01
-
-
Save dha-lo-jd/fed687f270c840eb1a46 to your computer and use it in GitHub Desktop.
居酒屋マシリーズ 居酒屋マとは、「プログラマー」を「調理師」に例えた時に、「飲食業に興味があるわけじゃない居酒屋バイト」レベルになってしまうような「プログラムに興味ないけどIT業界に入っちゃいました」という困ったプログラマのことである。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
import javax.xml.bind.DatatypeConverter; | |
/** | |
* ブラック居酒屋のバイト歴15年のバイトチーフ()「バイトを舐めるんんじゃねぇ!」 | |
*/ | |
public class IZAKAYA_Byte { | |
private static class MyClassLoader extends ClassLoader { | |
private static final String src = "CAFEBABE00000033003907000201000846697A7A42757A7A0700040100106A6176612F6C616E672F4F626A65637401000169010001490100083C636C696E69743E010003282956010004436F6465090001000B0C0005000601000F4C696E654E756D6265725461626C650100124C6F63616C5661726961626C655461626C650100063C696E69743E0A000300100C000E00080100047468697301000A4C46697A7A42757A7A3B0100046D61696E010016285B4C6A6176612F6C616E672F537472696E673B295609001600180700170100106A6176612F6C616E672F53797374656D0C0019001A0100036F75740100154C6A6176612F696F2F5072696E7453747265616D3B0A001C001E07001D0100136A6176612F696F2F5072696E7453747265616D0C001F00200100077072696E746C6E010004284929560A000100220C0013001408002401000946697A7A2042557A7A0A001C00260C001F0027010015284C6A6176612F6C616E672F537472696E673B295608002901000946697A7A2042757A7A08002B01000446697A7A08002D01000442757A7A08002F01000CEFBCA5EFBCB8EFBCA9EFBCB4010004617267730100135B4C6A6176612F6C616E672F537472696E673B010008616D61726953616E0100016B0100016A010007616D617269476F01000D537461636B4D61705461626C6501000A536F7572636546696C6501000D46697A7A42757A7A2E6A61766100210001000300000001000800050006000000030008000700080001000900000025000100000000000503B3000AB100000002000C00000006000100000003000D0000000200000001000E0008000100090000002F00010001000000052AB7000FB100000002000C00000006000100000001000D0000000C00010000000500110012000000090013001400010009000002B50002000500000149A70138B2000A06A20019B20015B2000AB6001BB2000A0460B3000A01B80021B1B2000A100FA00015B200151223B600251010B3000A01B80021B1B2000A3C033DA70024033EA700171D05A000068401FD1B06A2000711270F3E8403011D06A1FFEA8402011C1064A1FFDCB2000A3D033EA70028033604A70019150407A000068402FB1C08A2000811270F3604840401150408A1FFE78403011D1064A1FFD81BAA0000007500000000000000020000001900000037000000561C9A000EB200151228B60025A7006C1C990068B20015122AB60025A7005D1C9A000EB20015122CB60025A7004E1C99004AB20015B2000AB6001BA7003E1C9A000EB20015122CB60025A7002F1C99002BB20015B2000AB6001BA7001F1C9A000EB20015122CB60025A700101C99000CB20015B2000AB6001BB2000A0460B3000AB2000A1064A1FEC6B20015122EB60025B100000003000C000000D600350000000A0003000C000A000D0013000E001B000F001F00100020001200280013003000140035001500390016003A0018003E001A0043001D00480020004D002100500023005500240059001D0061001A006A002B006E002D0073003000790033007F00340082003600870037008C00300095002D009E003E00B8004300BC004400C4004500CB004600D3004800D6004D00DA004E00E2004F00E9005000F2005200F5005700F90058010100590108005A0111005C01140062011800630120006401270065013000670135000A0140006B0148006C000D00000048000700000149003000310000003E00F20032000600010040002A0033000600020045001C003400060003006E00C20035000600020070002E0033000600030076001F0034000600040036000000300019031C19FD00080101FC000401070802FA0007FC000E01FC000501080902FA0008FA001F0E0E0E0F0E0F0EF9000C0700010037000000020038"; | |
private static byte[] inputBytes(String str) throws IOException { | |
return DatatypeConverter.parseHexBinary(str); | |
} | |
private Class getFizzBuzzClass() throws IOException { | |
byte[] inputBytes = inputBytes(src); | |
Class cls = defineClass("FizzBuzz", inputBytes, 0, inputBytes.length); | |
return cls; | |
} | |
} | |
public static void main(String[] args) throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, | |
NoSuchMethodException, SecurityException { | |
// System.out.println(outputBytes()); | |
Class cls = new MyClassLoader().getFizzBuzzClass(); | |
Method method = cls.getMethod("main", String[].class); | |
method.invoke(null, new Object[] { | |
null | |
}); | |
} | |
private static byte[] inputBytes(String str) throws IOException { | |
return DatatypeConverter.parseHexBinary(str); | |
} | |
// private static String outputBytes() throws IOException { | |
// try (InputStream is = | |
// FizzBuzz.class.getResourceAsStream("FizzBuzz.class"); | |
// ByteArrayOutputStream bos = new ByteArrayOutputStream()) { | |
// int b = -1; | |
// while ((b = is.read()) != -1) { | |
// bos.write(b); | |
// } | |
// | |
// return DatatypeConverter.printHexBinary(bos.toByteArray()); | |
// } | |
// } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class API_Kansuu { | |
/* | |
* 使い方 | |
*/ | |
public static void main(String[] args) { | |
Integer[] args2 = new Integer[] { | |
0, 1 | |
};// 長さ2の配列を宣言 | |
System.out.println(Arrays.asList(args2)); | |
args2 = (Integer[]) new API_Kansuu().Hairetsu_Stretch(args2, 5);// 新たに長さ7の配列が生成される! | |
System.out.println(Arrays.asList(args2)); | |
} | |
public Object[] Hairetsu_Stretch(Object[] args, int newL) { | |
Object[] new_Hairetsu = null;// はじめにnullを代入する | |
if (args == null) {// nullだったら | |
args = new Object[256];// 配列を宣言する | |
} | |
if (args.length <= 0.1) {// 配列が無の時 | |
args = new Object[256];// 原因不明のエラーが起こるからこうしないといけない | |
} | |
if ((args[0] != null && args[0].getClass() == int.class) || (args[0] != null && args[0].getClass() == Integer.class)) {// int配列の時 | |
new_Hairetsu = new Integer[args.length + newL]; | |
// たまに原因不明のエラーで落ちるので究明中…Javaは奥が深い^^; | |
for (int i = 1; i <= args.length; i++) { | |
int numValue = (int) args[i - 1];// i番目の入れ物から数値を取り出します(配列は1番目が0から始まるので1を引きます) | |
new_Hairetsu[i - 1] = numValue; | |
} | |
} | |
if (args[0] != null && args[0].getClass() == String.class) {// String配列の時 | |
new_Hairetsu = new String[args.length + newL]; | |
// 上のコピペ…手抜きでごめんなさいm(_ _)m | |
for (int i = 1; i <= args.length; i++) { | |
String strValue = (String) args[i - 1];// i番目の入れ物から数値を取り出します(配列は1番目が0から始まるので1を引きます) | |
new_Hairetsu[i - 1] = strValue; | |
} | |
} | |
return new_Hairetsu; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FizzBuzz { | |
static int i = 0; | |
/* | |
* 数字を100まで増加させてFizzBuzz問題?に変換して行く | |
*/ | |
public static void main(String[] args) { | |
// ループする | |
for (; i < 100; i++) {// ローカル変数からstatic変数に移したため、変数を初期化しないように削除 | |
// ループ開始 | |
if (i < 3) { | |
System.out.println(i); | |
i++; | |
main(null);// 次のループに行くためにstaticな変数を増加させてmainを呼びなおす | |
return; | |
} | |
if (i == 15) { | |
System.out.println("Fizz BUzz"); | |
i = 16; | |
main(null);// 次のループに行くためにstaticな変数を増加させてmainを呼びなおす | |
return; | |
} | |
int amariSan = i; | |
// ループする | |
for (int k = 0; k < 100; k++) {// 最低100回ループすればよい | |
// ループ開始 | |
// ループする | |
for (int j = 0; j < 3; j++) { | |
// ループ開始 | |
// 3で割ったあまりを求めていく | |
if (j == 2) { | |
amariSan = amariSan - 3; | |
} | |
if (amariSan < 3) {// 3以下の数字があまりになる | |
j = 9999;// ループを強制終了 | |
} | |
} | |
// ループ終了 | |
} | |
// ループ終了 | |
int amariGo = i; | |
// ループする | |
for (int k = 0; k < 100; k++) {// 最低100回ループすればよい | |
// ループ開始 | |
// ループする | |
for (int j = 0; j < 5; j++) { | |
// ループ開始 | |
// 5で割ったあまりを求めていく | |
if (j == 4) { | |
amariGo = amariGo - 5; | |
} | |
if (amariGo < 5) {// 5以下の数字があまりになる | |
j = 9999;// ループを強制終了 | |
} | |
} | |
// ループ終了 | |
} | |
// ループ終了 | |
switch (amariSan) { | |
case 0: | |
/* | |
* ケース数が多いので5で割ったあまりはスイッチにしないほうが良いとのこと 知恵袋の回答者の方、多謝! | |
*/ | |
if (amariGo == 0) { | |
System.out.println("Fizz Buzz");// 3で割ったあまりが0で5で割ったあまりも0なのでフィジバズと出力 | |
} else if (amariGo != 0) { | |
System.out.println("Fizz");// 3で割ったあまりが0で5で割ったあまりが0ではないのでバズと出力 | |
} | |
break; | |
case 1: | |
/* | |
* ケース数が多いので5で割ったあまりはスイッチにしないほうが良いとのこと 知恵袋の回答者の方、多謝! | |
*/ | |
if (amariGo == 0) { | |
System.out.println("Buzz");// 3で割ったあまりが0ではなく5で割ったあまりが0でなので数値を出力 | |
} else if (amariGo != 0) { | |
System.out.println(i);// 3で割ったあまりが0ではなく5で割ったあまりが0ではないので数値を出力 | |
} | |
break; | |
case 2: | |
/* | |
* ケース数が多いので5で割ったあまりはスイッチにしないほうが良いとのこと 知恵袋の回答者の方、多謝! | |
*/ | |
if (amariGo == 0) { | |
System.out.println("Buzz");// 3で割ったあまりが0ではなく5で割ったあまりが0でなので数値を出力 | |
} else if (amariGo != 0) { | |
System.out.println(i);// 3で割ったあまりが0ではなく5で割ったあまりが0ではないので数値を出力 | |
} | |
break; | |
default: | |
/* | |
* ケース数が多いので5で割ったあまりはスイッチにしないほうが良いとのこと 知恵袋の回答者の方、多謝! | |
*/ | |
if (amariGo == 0) { | |
System.out.println("Buzz");// 3で割ったあまりが0ではなく5で割ったあまりが0でなので数値を出力 | |
} else if (amariGo != 0) { | |
System.out.println(i);// 3で割ったあまりが0ではなく5で割ったあまりが0ではないので数値を出力 | |
} | |
break; | |
} | |
} | |
// ループ終了 | |
System.out.println("EXIT");// エグジットで終了 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 居酒屋マがやってのけるループの書き方の一例 | |
*/ | |
public class IZAKAYA_Loop { | |
public static void main(String[] args) { | |
if (args == null || args.length < 0) { | |
return; | |
} | |
int numberGiven; | |
try { | |
numberGiven = Integer.parseInt(args[0]); | |
} catch (NumberFormatException e) { | |
e.printStackTrace(); | |
return; | |
} | |
// for (int i = 1; i <= numberGiven; i++) { | |
// if (isFizzBuzz(i)) { | |
// System.out.println("Fizz Buzz"); | |
// } else if (isFizz(i)) { | |
// System.out.println("Fizz"); | |
// } else if (isBuzz(i)) { | |
// System.out.println("Buzz"); | |
// } else { | |
// System.out.println(i); | |
// } | |
// } | |
/* | |
* ここから居酒屋マコード | |
*/ | |
int uwanose = 0;//ループ回数の上乗せ用int変数 | |
for (int i = 1; i < 1000; i++) { | |
numberGiven = numberGiven - 1;//番号を1消化 | |
if (numberGiven == -1) {//番号を消化しきったので処理終了 | |
return; | |
} | |
/* | |
* ループをリセットしつつ上乗せ変数を増加させて次のループに移行 | |
*/ | |
if (i == 999) { | |
i = 0; | |
uwanose = uwanose + 999; | |
} | |
/* | |
* 知恵袋からコピペ | |
*/ | |
if (isFizzBuzz(i + uwanose)) { | |
System.out.println("Fizz Buzz"); | |
} else if (isFizz(i + uwanose)) { | |
System.out.println("Fizz"); | |
} else if (isBuzz(i + uwanose)) { | |
System.out.println("Buzz"); | |
} else { | |
System.out.println(i + uwanose); | |
} | |
/* | |
* 知恵袋からコピペここまで | |
*/ | |
} | |
/* | |
* ここまで居酒屋マコード | |
*/ | |
} | |
private static boolean isBuzz(int i) { | |
return i % 5 == 0; | |
} | |
private static boolean isFizz(int i) { | |
return i % 3 == 0; | |
} | |
private static boolean isFizzBuzz(int i) { | |
return isFizz(i) && isBuzz(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment