Task
Write a program/function that when given a positive integer \$n\$ and a digit \$d\$ which is not 0 outputs a way to represent \$n\$ using only addition, subtraction, multiplication, exponentiation, division, concatenation, parenthesis and the digit \$d\$.
Examples
n = 6, d = 1 => (1 + 1) * (1 + 1 + 1)
n = 6, d = 1 => 1 + 1 + 1 + 1 + 1 + 1
n = 10, d = 1 => 1 || 1 - 1
n = 12, d = 1 => 1 || (1 + 1)
n = 64, d = 2 => 2 ^ (2 + 2 + 2)
n = 1, d = 9 => 9 / 9
Note: In the examples ||
represents concatenation
Output Format
- Concatenation must be explicit with a separate operator
- Output can be a string, list of operations and numbers or a list of lists in place of brackets.
- You may choose the precedence of the operators but it must be consistent for all outputs produced by your program/function
- Output may be in polish, reverse polish or infix notation but it must be consistent for all outputs produced by your program/function.
- You can use custom symbols for representing the digits and operations but the symbols used for representing the digits and operations should be distinct.
Scoring
This is code-challenge, Your score will be
100*B + S
Where B
is the number of bytes in the program/function, and S
is the sum of the number of times the digit \$d\$ appears in the representation of \$n\$ with the digit \$d\$ as returned by your program/function for all \$n \le 1000\$ and all \$d\$ from 1 to 9
Lowest score wins
Example: if your program is abcd
and all representation of \$n\$ returned by your program has 5 occurrences of \$d\$ then its score will be (4 * 100) + (5 * 1000 * 9) = 45400
Rules
- Your program/function should run deterministically, so that it always returns the same representation for a given \$n\$ and \$d\$ (and hence always gets the same score).
- Your answer must include not only your submission, but also the code you used to calculate the
S
part of its score. This need not be written in the same language as your submission, and will not be counted towards its byte count. You are encouraged to make it readable. - Your answer must include the precedence of the operators needed to evaluate the outputs produced by your program/function
- You must actually run your test program and calculate/verify your score before submitting your entry. If your submission runs too slowly for you to verify its score then it is not qualified to compete, even if you know what its score would be in principle.
Inspired by this video
21,1
as11+11-1
, when the optimal answer here would be(1+1)||1
) \$\endgroup\$ – Jo King♦ Feb 27 '20 at 3:36||
after those of+
and-
? \$\endgroup\$ – user92069 Feb 27 '20 at 5:40/
operator represent integer division? \$\endgroup\$ – RootTwo Feb 27 '20 at 23:26