Every piece of Mathemania code starts off with the number
2. From the
2, you can do the following operations:
e: Exponentiation. This command's default is squaring the number.
f: Factorial. This command's default is using the single factorial on the number (
using f on 2 = 2! = 2).
r: Root. This command's default is square-rooting the number.
c: Ceiling function.
l: Floor function.
To generate a number in Mathemania, you must string together these commands, which are performed left-to-right on the number
ef = (2^2)! = 4! = 24 rl = floor(sqrt(2)) = floor(1.4...) = 1 er = sqrt(2^2) = sqrt(4) = 2 efrrc = ceil(sqrt(sqrt((2^2)!))) = ceil(sqrt(sqrt(24))) = ceil(sqrt(4.89...)) = ceil(2.21...) = 3
r commands can be altered by extra Mathemania commands (which also start off with
2 as its "base" number) to generate different exponentiations, factorials and roots by placing brackets after the altered function and placing the Mathemania commands inside it.
For example, to cube a number instead of squaring it, you can put the command for
e like so:
e(efrrc) -> cube a number, "efrrc" = 3
NOTE: for our purpose, the factorial command (
f) start off with
2 as a single factorial. So if you do
f(efrrc), that will get evaluated to a double factorial, not a triple factorial.
n-factorials (e.g. double factorials = 2-factorial, triple factorial = 3-factorial etc.), the base number is multiplied by the number that is
n less than it, and
n less than that, and so on until the final number cannot be subtracted by
n without becoming
0 or negative.
7!! = 7 * 5 * 3 * 1 = 105 (repeatedly subtract 2, 1 is the last term as 1 - 2 = -1, which is negative) 9!!! = 9 * 6 * 3 = 162 (repeatedly subtract 3, 3 is the last term as 3 - 3 = 0, which is 0)
For more information, see here.
You can insert it anywhere, and it will get treated by Mathemania as a single function:
e(efrrc)rc = ceil(sqrt(2^3)) = ceil(2.82...) = 3
You're also allowed to nest these inside one another:
e(e(e)) = e(4th power) = (2^4)th power = 16th power
For an interpreter of Mathemania code, click here (cheers, @BradGilbertb2gills!)
Your task is to create a program that, when given a positive integer
n as input, generates a Mathemania program that when executed, returns
However, the Mathemania programs that you generate must be as small (golfed) as possible, and your final score is determined by the sum of the number of bytes in the generated Mathemania programs of the sample, which are the integers
10,100. The lowest score wins.
Rules and specs:
- Your program must output a valid Mathemania program for any positive integer, but only the numbers between
10,100will be tested.
- You are not allowed to output Mathemania programs that do not result in an integer. If you do so, your program is disqualified.
- For the commands
r, the Mathemania code inside those functions (e.g.
e(efrrc), where the
efrrcis the code inside the function) must evaluate to a positive integer above
2. If your program doesn't follow this rule, it is disqualified as well.
- Your program must return a Mathemania program for any one of the 101 test integers in at most 30 minutes on a modern laptop.
- Your program must return the same solution for any integer every time it is run. For example, when a program is given an input
5and it outputs
efrc, it must output that every time the input
- You may not hard-code any solutions for any positive integer.
- In order to fully maximise golfing potential in your output, your program should be able to handle arbitrarily large integers. It is not a requirement, though good luck if your language doesn't support this.
This is metagolf, so lowest score wins!