Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fibonacci {
- private static final int MAX_COUNT = 16;
- private static final String ALLOWED_CHARACTERS = "0002244455777777";
- private static final Map<Character, Integer> ALLOWED_MAP = allowedMap();
- public static String fibonacci(long fib1, long fib2) {
- String seq = "" + fib1 + fib2;
- for (int i = 0; i < 8; i++) {
- long newFib = fib1 + fib2;
- fib1 = fib2;
- fib2 = newFib;
- seq += newFib;
- if (seq.length() == MAX_COUNT && !containsNotAllowedNumbers(newFib))
- break;
- if (seq.length() > MAX_COUNT || containsNotAllowedNumbers(newFib)) {
- seq = "too long :/";
- break;
- }
- }
- return seq;
- }
- public static void main(String[] args) {
- int max = 7777;
- List<String> codes = new ArrayList<String>();
- for (int i = 1; i < max; i++) {
- for (int j = 1; j < max; j++) {
- long fib1 = i;
- long fib2 = j;
- if (containsNotAllowedNumbers(fib1)
- || containsNotAllowedNumbers(fib2))
- continue;
- String possible = fibonacci(fib1, fib2);
- if (!possible.equals("too long :/")) {
- if (rightNumberCount(possible)) {
- codes.add(possible);
- }
- }
- }
- }
- if (codes.size() <= 0)
- System.out.println("Code not found!");
- else {
- for (String string : codes) {
- System.out.println("!Phantom Code: " + string);
- }
- }
- System.exit(0);
- }
- private static boolean rightNumberCount(String possible) {
- System.out.println(possible);
- int nul = 0;
- int two = 0;
- int fou = 0;
- int fiv = 0;
- int sev = 0;
- int maxnul = 3;
- int maxtwo = 2;
- int maxfou = 3;
- int maxfiv = 2;
- int maxsev = 6;
- for (int i = 0; i < possible.length(); i++) {
- char c = possible.charAt(i);
- if (c == '0')
- nul++;
- else if (c == '2')
- two++;
- else if (c == '4')
- fou++;
- else if (c == '5')
- fiv++;
- else if (c == '7')
- sev++;
- }
- if (nul > maxnul) {
- System.out.println("0x" + nul);
- return false;
- } else if (two > maxtwo) {
- System.out.println("2x" + two);
- return false;
- } else if (fou > maxfou) {
- System.out.println("4x" + fou);
- return false;
- } else if (fiv > maxfiv) {
- System.out.println("5x" + fiv);
- return false;
- } else if (sev > maxsev) {
- System.out.println("7x" + sev);
- return false;
- }
- System.out.println("!Code found!");
- return true;
- }
- private static Map<Character, Integer> allowedMap() {
- Map<Character, Integer> map = new HashMap<Character, Integer>();
- for (int i = 0; i < ALLOWED_CHARACTERS.length(); i++) {
- char c = ALLOWED_CHARACTERS.charAt(i);
- Integer count = map.get(c);
- if (count == null)
- count = 1;
- map.put(c, count + 1);
- }
- return map;
- }
- private static boolean containsNotAllowedNumbers(long fib) {
- String str = String.valueOf(fib);
- return str.contains("1") || str.contains("3") || str.contains("6")
- || str.contains("8") || str.contains("9");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement