Challenge
Write a non-empty program/function p
that, given a non-empty input string s
, outputs the position of the first occurrence of each character of s
in the source code of p
.
For example, if your program is
main() { cout << magic << cin }
^0 ^5 ^10 ^15 ^20 ^25
and it receives an input abcd{
, the output should be
[1, x, 9, x, 7] (0-based) [2, x, 10, x, 8] (1-based)
Here, x
represents any output that is not a valid output for a character position (e.g., a negative number, 0
if you use 1-based indexing, NaN
, Inf
, the string potato
, a number greater than your program's length, etc).
Restrictions
Reading the source code is not allowed (like in a proper quine). The use of comments is allowed, but does count towards your score.
Input and output can be done in a reasonable format, but must be unambiguous (only additional delimiters, no rand
stream and claiming that the answer is somewhere in there), consistent (e.g., the x
from above should always be the same value) and human-readable; for example, a string or a character array. You can assume that the input is a string (or array) of printable ASCII characters; no need to handle the entire Unicode set.
Custom code-page or non-printable ascii in your code?
If your language uses a custom code-page (Jelly, APL, etc), you must take that into account (so a program €æÆ
must output [1, x, 2]
for an input €%æ
). Using only non-ASCII characters to output -1
always (since the input is ASCII-only) is not a valid solution. You may assume that your program natively accepts your custom codepage, i.e., if your program has a method of converting a character A
to an integer 65
(ASCII encoding), you may assume that it now converts the 65th character in your codepage to 65
.
Inspired on the following challenge: Positional Awareness
01030708070
? \$\endgroup\$