10
2
Write a filter that converts text from standard input to a representation of its Huffman tree on standard output. In as few characters as possible.
- you're free to consider newlines or not
- output format is free, as long as it's some human-readable encoding of a tree. s-exps, ascii-art and .png, all good. RPN, .dot, I'll smile or frown, but that ought to be ok. Program cores and/or raw pointers , no way.
- no canonicalization needed; if the characters are at the right depth, that's good enough.
Sample possible output for "this is an example of a huffman tree" (from wikipedia):
(((e . (n . (o . u))) . (a . (t . m))) .
(((i . (x . p)) . (h . s)) . (((r . l) . f) . #\space)))
I can't reproduce all possible valid outputs with human-readable representation combinations in here (the margin is a bit too thin), but what should check is which characters end up at which number of bits:
- 3 bits: a e [space]
- 4 bits: f h i m n s t
- 5 bits: l o p r u x
If [newline] is kept in, it appears appears in the "5 bits" level, but (any) two characters have to drop from there to 6 bits.
Why finishing that quick? There're only 2 answers so far. – FUZxxl – 2011-02-18T08:49:41.547
No, didn't know that. Is this written up somewhere? – J B – 2011-02-18T09:29:05.933
I tried it out, but strange enough I could change the accepted answer, even if accepted for half a year. They possibly changed the rules. – FUZxxl – 2011-02-18T09:52:44.753
@George Edison: Is this new? I remember this was different before. – FUZxxl – 2011-02-20T15:30:39.293