fork download
  1. public class main{
  2. public void main(String args){
  3. //Tanto el número mágico como la semilla son correctos
  4. Generador gen = new Generador(49374); //Iniciamos el generador con el número mágico
  5. gen.semilla = "wow.sinfocol.org"; //Inicializamos la semilla
  6. System.out.println(gen.wowHash("prueba wowHash")); //Imprimimos el hash
  7. //Probando con "prueba wowHash" el resultado bueno es 10113961485fe29c
  8. }
  9. }
  10.  
  11. private class Generador {
  12. private static String semilla = "";
  13. private long magicNumber = 0;
  14. private final BigInteger CERO = BigInteger.CERO;
  15. private final BigInteger UNO = BigInteger.ONE;
  16. private final BigInteger D6 = BigInteger.SIXTEEN;
  17. private final static char[] cambExp = {'f', 'e', 'd', 'c', 'b', 'a', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0'};
  18.  
  19. public Generador(byte magicNumber){
  20. magicNumber = magicNumber;
  21. }
  22.  
  23. public long wowHash(String str){
  24. long tmp = this.magicNumber;
  25. str += semilla;
  26. int i = 0;
  27. int len = str.length();
  28. while(i < len) tmp += (tmp << 3) + str.codePointbefore(i++);
  29. return Int2BaseR(BigInteger.valueOf(tmp), D6);
  30. }
  31.  
  32. private String Int2BaseR(BigInteger num, BigInteger base){
  33. if(num.compareTo(base.subtract(UNO)) < 0){
  34. return (num.mod(base).compareTo(CERO) == 0)? "": num.mod(base).toString();
  35. }else{
  36. return Int2BaseR( num.divide( base ), base) + cambBase( num.mod( base ).toString() );
  37. }
  38. }
  39.  
  40. private String cambBase(String num){
  41. return String.valueOf( cambExp[(int) num] );
  42. }
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class main is public, should be declared in a file named main.java
public class main{
       ^
Main.java:11: error: modifier private not allowed here
private class Generador {
        ^
Main.java:14: error: cannot find symbol
    private final BigInteger CERO = BigInteger.CERO;
                  ^
  symbol:   class BigInteger
  location: class Generador
Main.java:15: error: cannot find symbol
    private final BigInteger UNO = BigInteger.ONE;
                  ^
  symbol:   class BigInteger
  location: class Generador
Main.java:16: error: cannot find symbol
    private final BigInteger D6 = BigInteger.SIXTEEN;
                  ^
  symbol:   class BigInteger
  location: class Generador
Main.java:32: error: cannot find symbol
    private String Int2BaseR(BigInteger num, BigInteger base){
                             ^
  symbol:   class BigInteger
  location: class Generador
Main.java:32: error: cannot find symbol
    private String Int2BaseR(BigInteger num, BigInteger base){
                                             ^
  symbol:   class BigInteger
  location: class Generador
Main.java:4: error: incompatible types: possible lossy conversion from int to byte
        Generador gen = new Generador(49374); //Iniciamos el generador con el n?mero m?gico
                                      ^
Main.java:5: error: semilla has private access in Generador
        gen.semilla = "wow.sinfocol.org"; //Inicializamos la semilla
           ^
Main.java:14: error: cannot find symbol
    private final BigInteger CERO = BigInteger.CERO;
                                    ^
  symbol:   variable BigInteger
  location: class Generador
Main.java:15: error: cannot find symbol
    private final BigInteger UNO = BigInteger.ONE;
                                   ^
  symbol:   variable BigInteger
  location: class Generador
Main.java:16: error: cannot find symbol
    private final BigInteger D6 = BigInteger.SIXTEEN;
                                  ^
  symbol:   variable BigInteger
  location: class Generador
Main.java:28: error: cannot find symbol
        while(i < len) tmp += (tmp << 3) + str.codePointbefore(i++);
                                              ^
  symbol:   method codePointbefore(int)
  location: variable str of type String
Main.java:29: error: cannot find symbol
        return Int2BaseR(BigInteger.valueOf(tmp), D6);
                         ^
  symbol:   variable BigInteger
  location: class Generador
Main.java:41: error: incompatible types: String cannot be converted to int
        return String.valueOf( cambExp[(int) num] );
                                             ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
15 errors
stdout
Standard output is empty