a.k.a. You Can Output Anything With Labyrinth Or Hexagony™
In a recent restricted-source challenge, I could print any character with only half of the allowed digits with very small character count, by abusing the "digit commands" and modulo-256 output function. Now, it's about time to make a general metagolfer for this kind of challenges.
For the sake of simplicity, we only consider Labyrinth programs of the form
<digits>.@, i.e. construct a number, print it modulo 256 as character code, and halt. Also, the sequence of digits acts exactly like a number literal in this case.
Now let's assume we want to solve a restricted-source challenge in the form of:
Given the characters
.@and a subset of
0-9, print a character.
Given a subset of digits
D and the target character
c, find the shortest number
N which will solve the hypothetical challenge above. In other words,
N should satisfy the following:
- All the digits of
- The Labyrinth program
N.@prints the character
N % 256 == ord(c).
- The byte value of
ccan be anything between 1 and 255 inclusive.
- The byte value of
- Out of all possible
Ns satisfying the above, your program should output one that has the shortest length. If there are multiple possible answers, your program is free to output any of them.
You may take
c as a character or an integer (charcode), and digits in
D as integers or digit characters. Also, you may assume
D is already sorted.
Assume the answer exists. Note that some conditions will lead to "no answer", e.g. only odd digits are allowed but you need to print an even character, or vice versa. You may assume that such conditions will never be given as input.
Standard code-golf rules apply. The shortest code in bytes wins.
The value of
c is given as its character code.
D = [1, 2, 3, 4, 5] c = 1 => N = 1 c = 57 => N = 313 c = 254 => N = 254 c = 100 => N = 1124 or 4452 c = 107 => N = 1131, 2155, 2411, or 3435 D = [1, 2, 4, 6, 8] c = 58 => N = 826 c = 71 => N = 1111111 c = 255 => N = 26111 D =  c = 49 => N = 777777