I got a fixed set of variables and a set of valid operators (+,-,*,/,%). I want to build several valid math equations of the form v1 = v2 <operator> v3. However, the values for each variable should be randomly generated beforehand.
I got to the conclusion that a "smart" algorithm is needed because brute forcing is not effective enough. The code should be able to run on a Raspberry Pi 3, therefore the memory is quite limited.
Furthermore, the equations should all be different (not just a different order) and interesting, so no 0=5-5, 0=10*0, 1=3/3 etc. I think the values might need to be created while creating the functions, but they need to fit for all (previous and next) functions to be created.
private static Random random;
public static final int MAX = 5; // max value of any variable
public static final int FUNCTION_AMOUNT = 5;
private static char[] symbols = { 'ζ', 'ϑ', 'Ͽ', 'ς', 'ኂ' , 'ξ', 'Ծ', 'Φ', 'Ψ' };
private static int[] values = new int[symbols.length];
private static char[] operands = { '+', '-', '*', '/', '%' };
public static void generate(long seed) {
// create random
random = new Random(seed);
// generate values
for (int i = 0; i < values.length - 1; i++) {
values[i] = random.nextInt(MAX - 1);
}
// generate functions
for (int i = 0; i < FUNCTION_AMOUNT; i++) {
function = generateFunction();
}
Controller.log("Math module generation complete");
Controller.log("Math module:" + function);
}
private static String generateFunction() {
//nothing really worked yet
}
Aucun commentaire:
Enregistrer un commentaire