44
1
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
Does capitalisation matter? – user41805 – 2016-12-22T10:41:21.917
@KritixiLithos by default, yes.
– Martin Ender – 2016-12-22T10:41:55.040@KritixiLithos It does indeed. – Sanchises – 2016-12-22T10:54:49.220
If my program only uses indices 0 to 9, do I need a separator or could I output, e.g.,
01030708070? – Dennis – 2016-12-22T16:40:40.667@Dennis No, you do not. It's unambiguous, consistent and human-readable. Requiring a separator would not add anything interesting to the challenge, so by all means abuse your low byte count. ;) – Sanchises – 2016-12-22T16:43:12.103
Why do I use 05AB1E for quine challenges? I know it's not meant for it... – Magic Octopus Urn – 2018-04-02T17:12:48.077