Very simplistic solution. recursively partitions sorted frequencies to build the huffman tree: % ./huffman.rb I want this message to get encoded! Encoded: 11001000 11111000 01010010 00001011 01111100 01100011 10100101 10111000 01001001 00001010 11000100 10010100 00001101 01101010 11100010 01100011 1000 35 => 17 (51%) Code is rather straight forward: http://pastie.caboo.se/61225 -- Posted via http://www.ruby-forum.com/.