The task is simple. You're given an arbitrary string message. Return that message prefixed with a number, such that the length of that number plus the message equals the number. In other words, the length in your output must be the total length of your output.
If multiple candidates exist, you can output any of them.
For example, take the following message: pull the other one
, with a length of 18. Your final output should be 20
+ pull the other one
, because the total length of 20
+ the total length of pull the other one
is 20 ASCII characters.
Restrictions/clarifications:
- Your input and output can be given by any convenient method.
- The outputted length can be encoded in any way you like, as long as the encoding can represent any arbitrary positive number, and the encoding is consistent. You can, for example, output
10111
+pull the other one
(10111 is 23 in binary, and the total length is 23). This also extends to types: e.g. a tuple of(int, string)
is accepted as output, as long as you specify the encoding the integer must have. - The input string can also have any encoding you like (well, except for the encoding in this question).
- Your program should be able to handle at least all messages of length <= 1,048,575 (2^20-1).
- The program can be a full program or just a function; either is fine.
- Standard loopholes are forbidden.
- Shortest code wins.
Some more test cases:
# base 10
"hello world" -> "13" + "hello world"
"the axes" -> "9" + "the axes"
"the axes" -> "10" + "the axes" # both of these are valid outputs
"" -> "1" + "" # the empty message should result in simply the output "1"
# base 2
"hello world" -> "1111" + "hello world"
"test" -> "111" + "test"
"test" -> "1000" + "test" # both of these are valid outputs
"" -> "1" + "" # the empty message can result in simply the output "1"
"" -> "10" + "" # in binary, this is also a valid result for the empty message
10
is also a valid output for the empty message using base 2...? \$\endgroup\$10theaxes
is also acceptable output in this challenge, and not the other one. It is likely a dup, but I'm not sure if the difference between prepending and appending is suitably large enough. \$\endgroup\$10something
or100reallylongmessageof98length
instead of11something
or101...
. \$\endgroup\$