ArdentScript is a simple problem generator system, designed to be simple but versatile.
For some quick examples of what this is capable of, check out src/__tests__/interpolation.ts.
A variable is a "template" for generating a value.
Please check the typescript typings in src/generator.ts for the most up-to-date information on how variables should be structured and what kind of variable definitions are available.
As of 2020-09-14, the following variables types are available:
-
RANDOMINT: A random integer in [min,max). -
RANDOMFLOAT: A random floating point number in [min,max). IfnumDigitsis specified, the result will be rounded to that many digits after the decimal point.- It is generally recommended to set such a value as to avoid floating point rounding issues.
-
EVALUATE: Evaluateexpressionusing the other variables.- This variable must come after all the variables it depends on.
-
SHUFFLEJOIN: Given a list ofoperands, shuffle them, instantiate them using the existing variables, and then join the operands together using the specifiedoperator. Note thatoperatorandoperanddo not have to be valid operators and operands. The string processing works regardless.
A variable may optionally specify a name to improve readability. By default, numbers are named using their order - the first variable would be named 1, the second would be named 2, and so on.
A template is exactly what it sounds like - a template for generating something.
To specify part of the template that would be replaced by the value of a variable, use curly braces {}.
For example, '{x} + 1', with x = '12', would be instantiated to '12 + 1'.
Any string is applicable. Using the example above, if x = '3 + 8', the resulting string would be 3 + 8 + 1.
To insert an actual curly brace into the text, use double-curly braces {{ and }}.
Internally, ArdentScript uses mathjs to evaluate and simplify expressions.
The overall flow of instantiating a problem is
- The variables are instantiated into concrete values.
- The question and solution templates are instantiated using the values generated from step 1.
- Depending on the solution type,
mathjsoperates on the solution expression from step 2.
Go to https://mathjs.org/ and use the demo panel to examine what kinds of expressions and functions are usable by mathjs.
Some common expressions are:
pi,e- constantssqrt()- square rootabs()- absolute valuesin(),cos(), etc. - common trig operators (in radians)atan2()- two-argument atan
At its core, ArdentScript is mostly a string processing library. Although the results often have meanings attached to them, ultimately, use those results however you want!