Last active
August 29, 2015 14:08
-
-
Save AgentK20/8e7aa5b66743792433ca to your computer and use it in GitHub Desktop.
He wanted to calculate the modulo of some numbers.
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
package net.hypixel; | |
import java.math.BigInteger; | |
import java.util.ArrayList; | |
public class MeeclesMath { | |
public static BigInteger starting = BigInteger.valueOf(349870850435529083L); | |
public static void main(String[] args) { | |
int cores = Runtime.getRuntime().availableProcessors(); | |
ArrayList<CalculationThread> threads = new ArrayList<>(); | |
BigInteger inc = BigInteger.valueOf(cores*200009); | |
for(int i=0; i<cores; i++) { | |
threads.add(new CalculationThread(i, inc)); | |
} | |
for(CalculationThread thread : threads) { | |
thread.start(); | |
} | |
while(!Thread.interrupted()) { | |
System.out.println("Sleeping..."); | |
try { | |
Thread.sleep(30000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
break; | |
} | |
for(CalculationThread thread : threads) { | |
System.out.println("Thread "+thread.getName()+" at "+thread.i.toString()); | |
} | |
} | |
} | |
public static class CalculationThread extends Thread { | |
private static final BigInteger SEARCH_A = BigInteger.valueOf(160009); | |
private static final BigInteger MATCH_A = BigInteger.valueOf(42873); | |
private static final BigInteger SEARCH_B = BigInteger.valueOf(70009); | |
private static final BigInteger MATCH_B = BigInteger.valueOf(29303); | |
private static final BigInteger SEARCH_C = BigInteger.valueOf(30013); | |
private static final BigInteger MATCH_C = BigInteger.valueOf(15340); | |
private static final BigInteger SEARCH_D = BigInteger.valueOf(19997); | |
private static final BigInteger MATCH_D = BigInteger.valueOf(15165); | |
private static final BigInteger SEARCH_E = BigInteger.valueOf(10009); | |
private static final BigInteger MATCH_E = BigInteger.valueOf(5119); | |
private static final BigInteger SEARCH_F = BigInteger.valueOf(7001); | |
private static final BigInteger MATCH_F = BigInteger.valueOf(2027); | |
private static final BigInteger SEARCH_G = BigInteger.valueOf(4099); | |
private static final BigInteger MATCH_G = BigInteger.valueOf(1184); | |
private static final BigInteger SEARCH_H = BigInteger.valueOf(2039); | |
private static final BigInteger MATCH_H = BigInteger.valueOf(689); | |
private static final BigInteger SEARCH_I = BigInteger.valueOf(1009); | |
private static final BigInteger MATCH_I = BigInteger.valueOf(858); | |
private static final BigInteger SEARCH_J = BigInteger.valueOf(691); | |
private static final BigInteger MATCH_J = BigInteger.valueOf(652); | |
private static final BigInteger SEARCH_K = BigInteger.valueOf(397); | |
private static final BigInteger MATCH_K = BigInteger.valueOf(343); | |
private static final BigInteger SEARCH_L = BigInteger.valueOf(191); | |
private static final BigInteger MATCH_L = BigInteger.valueOf(130); | |
private static final BigInteger SEARCH_M = BigInteger.valueOf(29); | |
private static final BigInteger MATCH_M = BigInteger.valueOf(4); | |
private static final BigInteger SEARCH_N = BigInteger.valueOf(13); | |
private static final BigInteger MATCH_N = BigInteger.valueOf(8); | |
private static final BigInteger SEARCH_O = BigInteger.valueOf(3); | |
private static final BigInteger MATCH_O = BigInteger.valueOf(2); | |
private static final BigInteger SEARCH_P = BigInteger.valueOf(2); | |
private static final BigInteger MATCH_P = BigInteger.valueOf(1); | |
private final BigInteger incrementer; | |
private BigInteger i = starting; | |
public CalculationThread(int multiplier, BigInteger incrementer) { | |
super("Calculation thread "+multiplier); | |
this.incrementer = incrementer; | |
this.i = this.i.add(BigInteger.valueOf(158045+(multiplier*200009))); | |
} | |
@Override | |
public void run() { | |
for(; ; i = i.add(incrementer)) { | |
if( | |
i.mod(SEARCH_A).equals(MATCH_A) && | |
i.mod(SEARCH_B).equals(MATCH_B) && | |
i.mod(SEARCH_C).equals(MATCH_C) && | |
i.mod(SEARCH_D).equals(MATCH_D) && | |
i.mod(SEARCH_E).equals(MATCH_E) && | |
i.mod(SEARCH_F).equals(MATCH_F) && | |
i.mod(SEARCH_G).equals(MATCH_G) && | |
i.mod(SEARCH_H).equals(MATCH_H) && | |
i.mod(SEARCH_I).equals(MATCH_I) && | |
i.mod(SEARCH_J).equals(MATCH_J) && | |
i.mod(SEARCH_K).equals(MATCH_K) && | |
i.mod(SEARCH_L).equals(MATCH_L) && | |
i.mod(SEARCH_M).equals(MATCH_M) && | |
i.mod(SEARCH_N).equals(MATCH_N) && | |
i.mod(SEARCH_O).equals(MATCH_O) && | |
i.mod(SEARCH_P).equals(MATCH_P)) { | |
System.out.println(i+" matches"); | |
System.exit(0); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment