1
What is the most compact way to encode/save DNS names in memory?
For example, storing "www.google.com" as a string in .NET will result in the object being encoded as UTF-16, and it will consume twice as much memory as plain ASCII... but for the purpose of storing DNS names, ASCII is overkill.
The only characters that are needed are:
- A..Z (case insensitive)
- 0..9
- Hyphen
- underscore
- period
- Asterisk (not legal DNS, but used in ACLs such as *.google.com) always as a leading character, never elsewhere.
A total of 40 characters.. which fits within single byte with plenty room to spare.
My code golf question/challenge is what is the most compact way to store a string of characters in memory and maximizing in memory storage?
The inspiration for this challenge came from this blog entry.
1How do you win the competition? – beary605 – 2012-10-21T06:44:40.950
3You meant UTF-16 for the .NET framework. In UTF-8, this name would take up just as much as ASCII. – Mr Lister – 2012-10-21T07:00:35.277
Try http://cs.stackexchange.com/ - there's probably already a question about basic information theory which would tell you all you need to know.
– Peter Taylor – 2012-10-21T08:01:15.513http://en.wikipedia.org/wiki/Kolmogorov_complexity? – beary605 – 2012-10-21T15:48:11.640
Actually, underscores are not allowed in DNS names. RFC 3696
– Mormegil – 2012-10-21T18:26:57.2431As stated this looks like a question for Stack Overflow (that is, it is a question). CodeGolf.SE is a plce for playing certain programming games. It would be essentially trivial to turn this into a [code-golf]---you just add the tag (and probably the one @beary suggests as well) and resign yourself to getting answer many languages. But I am closing until that is done just to encourage you to read the FAQ before posting to a new Stack Exchange site. Flag when you are ready for this to be re-opened. – dmckee --- ex-moderator kitten – 2012-10-21T19:10:09.317