18
1
Many programming languages are written using solely printable ASCII, tabs and newlines. These 97 characters are then stored in 8-bit bytes (which are actually capable of holding 256 different characters!), which is just terribly inefficient - especially in code-golfing, where every byte counts! In this challenge, you will be able to reduce your score by using base conversion.
Challenge
Your program/function takes a string or character array as input, which it then interprets as a base-97 number. It then converts this to a base-256 number, and counts the number of symbols (i.e., bytes) necessary to represent this number. This count will be the output/return value of your program/function.
A simple example using base-2 and base-10 (binary and decimal): if the input is 10110
, the output would be 2, since 101102=2210 (two digits necessary to represent output). Similarly, 11012 becomes 1310, giving an output of 2 as well, and 1102 becomes 610, so then the output would be 1.
The input string can contain all 95 printable ASCII characters , as well as newline \n
and literal tab \t
, which creates a source alphabet of 97 symbols for your base conversion. The exact alphabet will thus be (substituting the \t
and \n
with actual literal tab and newline; note the literal space following the newline):
\t\n !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Note that the order of this alphabet is important: for example, base-97 \t
corresponds to decimal 0
, and !
corresponds to decimal 3
.
Some testcases: (you do not need to handle an empty string)
Input Output
'example@domain.com' 15
'All your base are belong to us!' 26
' abcd' 9
'~ abcd' 10
'ABCDEFGHIJK' 9
'zyxwvutsrpq' 10
'{".~"}.~' 7
'\t\t\t\t\t\t\t\t' 1 (with \t a literal tab; the result is 0, which can be represented with 1 byte)
'!\t\t\t\t\t\t\t\t' 7 (with \t a literal tab)
Scoring
If your entry uses only printable ASCII, newline and/or tab: The score of your program will be the output of your program, when given its own source code as input.
If your entry uses any characters that are not printable ASCII, newline or tab: The score of your program is simply the number of bytes, like in code-golf.
3
If you have a better title suggestion than this outdated meme, feel free to post it in the comments!
– Sanchises – 2017-08-15T08:51:27.410Did you realize that this challenge could be won with a lenguage answer consisting of only tabs. – pppery – 2017-08-15T13:48:35.853
@ppperry To be honest, I have very little patience for such answers. Yes, I did realize this, but until someone can actually store the program on their system, it's not going to get my upvote. – Sanchises – 2017-08-15T14:03:13.097