fork(2) download
  1. import java.math.BigInteger;
  2. import java.util.Random;
  3.  
  4. class StringToSeed implements Runnable
  5. {
  6.  
  7. private String targetString;
  8. private long min, max;
  9.  
  10. public StringToSeed(String targetString, long min, long max)
  11. {
  12. this.targetString = targetString;
  13. this.min = min;
  14. this.max = max;
  15.  
  16. System.out.println("Core: " + min + " to " + max);
  17. }
  18.  
  19. public static void main(String[] args)
  20. {
  21. System.out.println(getASeed("martijn"));
  22. }
  23.  
  24. public static long getASeed(String str)
  25. {
  26. BigInteger max = new BigInteger(Long.toString(Long.MAX_VALUE));
  27. BigInteger min = new BigInteger(Long.toString(Long.MIN_VALUE));
  28.  
  29. BigInteger amount = max.subtract(min);
  30. int cores = Runtime.getRuntime().availableProcessors();
  31. BigInteger chunkSizePerCore = amount.divide(new BigInteger(Integer.toString(cores)));
  32.  
  33. System.out.println("Cores: " + cores);
  34. System.out.println("Seeds/Core: " + chunkSizePerCore);
  35.  
  36. for (int i = 0; i < cores; ++i)
  37. {
  38. StringToSeed sts = new StringToSeed(str, min.add(chunkSizePerCore.multiply(BigInteger.valueOf(i))).longValue(), min.add(chunkSizePerCore.multiply(BigInteger.valueOf(i + 1))).longValue());
  39. Thread t = new Thread(sts);
  40. t.start();
  41. }
  42.  
  43. return 0;
  44.  
  45. }
  46.  
  47. @Override
  48. public void run()
  49. {
  50. Random r = new Random();
  51. char[] str = targetString.toCharArray();
  52. seeds: for (long l = min; l != max; l++)
  53. {
  54. r.setSeed(l);
  55. for (int i = 0; i < str.length; i++)
  56. {
  57. if (r.nextInt(26) + 'a' != str[i])
  58. continue seeds;
  59. }
  60. System.out.println(l);
  61. return;
  62. }
  63. throw new RuntimeException();
  64. }
  65. }
  66.  
Time limit exceeded #stdin #stdout 5s 381632KB
stdin
Standard input is empty
stdout
Cores: 4
Seeds/Core: 4611686018427387903
Core: -9223372036854775808 to -4611686018427387905
Core: -4611686018427387905 to -2
Core: -2 to 4611686018427387901
Core: 4611686018427387901 to 9223372036854775804
0