-1
Task
The task is to convert a string to a number. It must accept the string via stdin and output the number via stdout.
You convert a string to a number by replacing each letter of the string by its index (mind that you don't need to replace it with the index, that's just an example. You are allowed to replace it with anything you like, as long as the output is decodable) in the following list (you don't need to convert any other characters):
Characters: abcdefghijklmnopqrstuvwxyz1234567890
(the input will only either be lowercase letters, or/and a number).
Additionally, you must make the output decodable, so if you have output 0
for input a
, and somebody inputs bl
, then the output will be something like 111
. This is not decodable since the program might interpret it as bbb
or lb
or bl
. You might make it decodable by making sure the the number that each character outputs always has a length of 2. Any other way of making sure your output is decodable is allowed, but you must explain how one would decode the output in your answer.
Standard loopholes are not allowed. This is code golf, so shortest code wins!
EDIT: By decodable, just to clarify, I mean that you can convert the output back into the input. Your program doesn't need to feature decoding features, only encoding.
Examples
Input Output
a 00
ab 0001
1 26
4
Welcome to PPCG! This is not a bad challenge, especially as your first, but I suggest using the Sandbox to get feedback on your future challenges before you post them.
– El'endia Starman – 2016-09-01T16:42:42.3431
You much convert a string to a number by replacing each letter of the string by its index (mind that you don't need to replace it with the index, that's just an example. You are allowed to replace it with anything you like, as long as the output is decodable)
What exactly does that mean? Are we suppose to replace each letter of the string by its index or not? – James – 2016-09-01T16:45:08.2171You don't need to, no. Anything that is decodable works. – Okx – 2016-09-01T16:46:20.033
1"It must accept the string via stdin and output the number via stdout." Any reason for this restriction? Commonly any I/O methods appropriate to the given language is acceptable, which would include e.g. command-line args in many cases. – Digital Trauma – 2016-09-01T17:07:12.460
1what's stopping us just doing base36 conversion? – Blue – 2016-09-01T17:10:17.157
Can the input be empty? – Ian Chew – 2016-09-01T17:16:53.867
@muddyfish I think the fact that a string prepended with zeros returns the same output as the string - e.g.
int("abc",36) == int("0abc",36)
– Jonathan Allan – 2016-09-01T19:00:35.233