diff options
Diffstat (limited to 'src/distractionless/arithmetic_tasks.cljd')
-rw-r--r-- | src/distractionless/arithmetic_tasks.cljd | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/distractionless/arithmetic_tasks.cljd b/src/distractionless/arithmetic_tasks.cljd new file mode 100644 index 0000000..e7357d9 --- /dev/null +++ b/src/distractionless/arithmetic_tasks.cljd @@ -0,0 +1,25 @@ +(ns distractionless.arithmetic-tasks) + +(def ^:private task-types [:addition :subtraction :multiplication]) + +(defn gen-task [] + {:type (rand-nth task-types) + :numbers [(inc (rand-int 20)) (inc (rand-int 20))]}) + +(defn- type->function [type] + (condp = type + :addition + + :subtraction - + :multiplication *)) + +(defn type->str [type] + (condp = type + :addition "+" + :subtraction "-" + :multiplication "*")) + +(defn test-result? [task input] + (= input + ((type->function (:type task)) + (first (:numbers task)) + (second (:numbers task))))) |