diff --git a/alapmuveleti/addsub.js b/alapmuveleti/addsub.js index 37ea32b..1030b68 100644 --- a/alapmuveleti/addsub.js +++ b/alapmuveleti/addsub.js @@ -12,6 +12,9 @@ function precompute_add_sub_operands() { for (c = 2 * min_num; c <= max_num; c++) { for (a = min_num; a <= c - min_num; a++) { b = c - a; + if (b > max_2nd_operand) { + continue + } // count things like 20-13 as a "10 crossing" (although it is technically not) if ((max_num == 20) && (c == 20) && (a > 10)) { crossing_10s.push({ a, b, c }); @@ -27,7 +30,7 @@ function precompute_add_sub_operands() { } } -// returns the elements of a sequence in a random order +// returns the elements of a sequence in random order class InRandomOrder { constructor(sequence) { this.sequence = randoSequence(sequence); @@ -49,19 +52,13 @@ class AddSub { this.crossing_10_ratio = get_float_input(this.short_name + "_10crossings_ratio") / 100.0; } - filter(a, b, c) { - return true - } - // returns the next random operation - next() { - do { - if (Math.random() < this.crossing_10_ratio) { - var { a, b, c } = this.operands_crossing_10.next(); - } else { - var { a, b, c } = this.operands_not_crossing_10.next(); - } - } while (!this.filter(a, b, c)); + next(_) { + if (Math.random() < this.crossing_10_ratio) { + var { a, b, c } = this.operands_crossing_10.next(); + } else { + var { a, b, c } = this.operands_not_crossing_10.next(); + } return this.render(a, b, c); } } @@ -72,23 +69,14 @@ class Addition extends AddSub { return [a, '+', b, '=', c]; } - filter(a, b, c) { - return b <= max_2nd_operand; - } - get short_name() { return "add"; } } // Generates random substractions class Subtraction extends AddSub { render(a, b, c) { - return [c, '-', a, '=', b]; + return [c, '-', b, '=', a]; } - filter(a, b, c) { - return a <= max_2nd_operand; - } - - get short_name() { return "sub"; } } diff --git a/alapmuveleti/columns.js b/alapmuveleti/columns.js new file mode 100644 index 0000000..e83ec8b --- /dev/null +++ b/alapmuveleti/columns.js @@ -0,0 +1,138 @@ +// Generates the next random operation in a column +class Column { + constructor(x, all_op_generators) { + this.op_generators = all_op_generators.filter( + op => { + return get_bool_input(`${op.short_name}_${x + 1}`); + } + ); + + if (0 == this.op_generators.length) { + this.op_generators = all_op_generators.slice(); // shallow copy + } + + this.random_missing_operand = get_bool_input(`random_missing_operand_${x + 1}`); + } + + next() { + let missing_pos = 4; + if (this.random_missing_operand) { + missing_pos = rando([0, 2, 4]).value; + } + + let op = rando(this.op_generators).value.next(missing_pos / 2); + op[missing_pos] = "__"; + return op; + } +} + +function rebuild_all() { + let interval = get_radiobutton_value("allowed_interval"); + switch (interval) { + case "100-beginner": { + max_num = 100; + max_2nd_operand = 9; + break; + } + case "100": { + max_num = 100; + max_2nd_operand = max_num; + break; + } + case "20": { + max_num = 20; + max_2nd_operand = max_num; + break; + } + default: + max_num = 10; + max_2nd_operand = max_num; + console.error("Invalid allowed_interval (szamkor) value:", interval); + break; + } + precompute_add_sub_operands(); + rebuild_table(); +} + + +function rebuild_table() { + // create a generator for all valid operations + var op_generators = [ + new Addition(), + new Subtraction(), + new Multiplication(), + new Division() + ]; + + // collect operation generators for each column + let columns = []; + for (let x = 0; x < column_cnt; x++) { + columns.push(new Column(x, op_generators)); + } + + // save settings to cookie + // NOTE: the lines above can actually modify the settings + save_settings(); + + // rewrite the table of exercises + for (let x = 0; x < column_cnt; x++) { + var tbl = document.getElementById(`exercises_${x + 1}`); + tbl.innerHTML = ''; + for (let y = 0; y < 25; y++) { + const tr = tbl.insertRow(); + parts = columns[x].next(); + for (const part of parts) { + const td = tr.insertCell(); + td.appendChild(document.createTextNode(part)); + } + } + } +} + +function build_column_settings() { + + var tbl = document.getElementById('per_column_settings'); + tbl.innerHTML = ` + + Művelettípusok kiválasztása oszloponként + (egyszerre több is választható): + + +`; + const tr = tbl.insertRow(); + for (let x = 1; x <= column_cnt; x++) { + const td = tr.insertCell(); + td.innerHTML = ` + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
+
+ + +
+`; + } +} diff --git a/alapmuveleti/index.html b/alapmuveleti/index.html index 8bb141f..e766aed 100644 --- a/alapmuveleti/index.html +++ b/alapmuveleti/index.html @@ -4,220 +4,27 @@ + Alapműveleti teszt - - + + - +

Az alábbi beállításokkal tudod befolyásolni, hogy milyen teszt készüljön. Ha a beállítások megvátoztatása után nem készít magától új feladatlapot, akkor nyomd meg az "Újat kérek!" gombot.
diff --git a/alapmuveleti/muldiv.js b/alapmuveleti/muldiv.js new file mode 100644 index 0000000..bddc87e --- /dev/null +++ b/alapmuveleti/muldiv.js @@ -0,0 +1,52 @@ + + + + + + +// Common base class for generating random multiplications and divisions +class MulDiv { + constructor() { + let triplets = []; + let a, b, c; + for (a = min_mul_operand; a <= max_mul_operand; a++) { + if (mul_tables.includes(a)) { + for (b = min_mul_operand; b <= max_mul_operand; b++) { + c = a * b; + triplets.push({ a, b, c }); + } + } + } + this.operands = new InRandomOrder(triplets); + } + + // returns the next random operation + next(missing_pos) { + var { a, b, c } = this.operands.next(); + return this.render(a, b, c, missing_pos); + } +} + +// Generates random additions +class Multiplication extends MulDiv { + render(a, b, c, missing_pos) { + if (missing_pos == 0) { + return [b, '⋅', a, '=', c]; + } + return [a, '⋅', b, '=', c]; + } + + get short_name() { return "mul"; } +} + +// Generates random substractions +class Division extends MulDiv { + render(a, b, c, missing_pos) { + if (missing_pos == 1) { + return [c, ':', b, '=', a]; + } + return [c, ':', a, '=', b]; + } + + get short_name() { return "div"; } +} diff --git a/alapmuveleti/styles.css b/alapmuveleti/styles.css new file mode 100644 index 0000000..099b8d3 --- /dev/null +++ b/alapmuveleti/styles.css @@ -0,0 +1,61 @@ + table { + border: none; + border-collapse: collapse; + table-layout: fixed; + width: 100%; +/* margin-top: 0.1cm;*/ + /*margin: 1cm;*/ + } + + table.exercises { + width: auto; +/* border: 1px solid red;*/ + } + + table.exercises td { + padding-right: 0.3em; + text-align: right; + } + + td.columns { +/* border-right: 1px solid black;*/ + } + + + th, + td { + border: none; + /* 1px solid; */ + font-size: 16pt; + font-family: Arial; + height: 28pt; + } + + @media screen { + + .settings { + font-size: 14pt; + font-family: Arial; + margin: 0; + } + + div.settings { + border: 1px solid; + padding: 10px; + } + + table.settings td, + th { + height: auto; + text-align: left; + font-size: 14pt; + font-family: Arial; + } + + } + + @media print { + .settings { + display: none; + } + } \ No newline at end of file