Hashtron inference: Difference between revisions
m
Corrected the program so that it produces the correct output.
m (Reposted a corrected program.) |
m (Corrected the program so that it produces the correct output.) |
||
Line 718:
=={{header|Java}}==
▲<syntaxhighlight lang="java" line>
public class Main {
public static long inference(
long out = 0;
// Check if the program is empty
if ( program.length == 0 ) {
return out;
}
// Iterate over the bits
for (
input = hash(input, ss, maxx);
for (
maxx -= max;
input = hash(input, s, maxx);
Line 743:
input &= 1;
if (input != 0) {
}
}
return out;
}
public static
// Mixing stage, mix input with salt using subtraction
long m = (n - s) & 0xFFFFFFFFL;
Line 767 ⟶ 768:
// Modular stage using Lemire's fast alternative to modulo reduction
return (int) ( ( ( m * max_val ) >>> 32 ) & 0xFFFFFFFFL );
}
public static void main(String[] args) {
int command = 42;
▲ long bits = 64;
long result = inference(command, bits, program);
System.out.println(Long.toUnsignedString(result));
}
}
===Both Demos===
|