fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] buckets = new int[10];
  13. for (int i = 0; i < 10; i++)
  14. buckets[i] = 0;
  15.  
  16. for (int i = 0; i < 1000; i++) {
  17. String id = String.format("130770%s0020", i);
  18. long l = Long.parseLong(id);
  19. int partition = (int) f(l);
  20. buckets[partition] = buckets[partition] + 1;
  21. }
  22.  
  23. for (int i = 0; i < 10; i++)
  24. System.out.print(buckets[i] + " ");
  25. }
  26. private static long f(long l) {
  27. return Math.abs(Long.toString(l).hashCode()) % 10;
  28. }
  29.  
  30. }
Success #stdin #stdout 0.26s 47912KB
stdin
Standard input is empty
stdout
100 100 100 100 100 100 100 100 100 100