/**
* The MIT License (MIT)
*
* Copyright (c) 2017 D3v3l0p3d_0n3
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package ru.beykerykt.bullsandcows.base.utils;

import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class GameUtils {

	private static ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();

	public static String generateRandomCode() {
		Random rand = new Random();
		int target = 0;
		while (hasDupes(target = (rand.nextInt(9000) + 1000)))
			;
		String targetStr = String.valueOf(target);
		return targetStr;
	}

	public static boolean hasDupes(int num) {
		boolean[] digs = new boolean[10];
		while (num > 0) {
			if (digs[num % 10])
				return true;
			digs[num % 10] = true;
			num /= 10;
		}
		return false;
	}

	public static ScheduledExecutorService getExecutorService() {
		if (es == null || es.isShutdown()) {
			es = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
		}
		return es;
	}
}
@@ -1165,16 +1165,67 @@
 utils;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A
 import j
@@ -1241,16 +1241,16 @@
 Random;%0A
-
 import j
@@ -1452,16 +1452,173 @@
 cutor();
+%0A%09public static int CODE_POWER%5B%5D = %7B 0, 1, 2, 3, 4, 5, 6 %7D;%0A%09public static int CODE_POWER_LENGTH = CODE_POWER.length - 1;%0A%09public static int CODE_LENGTH = 4;
 %0A%0A%09publi
@@ -2014,24 +2014,24 @@
  /= 10;%0A%09%09%7D%0A
-
 %09%09return fal
@@ -2034,24 +2034,393 @@
  false;%0A%09%7D%0A%0A
+%09public static List%3CString%3E getAllCodes(int length) %7B%0A%09%09List%3CString%3E list = new ArrayList%3CString%3E();%0A%09%09for (int i = 0; i %3C length; i++) %7B%0A%09%09%09for (int j = 0; j %3C length; j++) %7B%0A%09%09%09%09for (int k = 0; k %3C length; k++) %7B%0A%09%09%09%09%09for (int l = 0; l %3C length; l++) %7B%0A%09%09%09%09%09%09String code = String.valueOf(i + j + k + l);%0A%09%09%09%09%09%09list.add(code);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return list;%0A%09%7D%0A%0A
 %09public stat

implement get all codes from N length