From: Luke Cowell Date: 2009-05-19T13:53:39+09:00 Subject: Re: Encyclopedia Construction (#205) Here's my solution: http://www.pastie.org/482422 Usage: e = Encyclopedia.new(articles) e.volumes(20) #<-- how many volumes should it be condensed to? pp e.hash puts e.dump #<-- this will print a nice little chart to help you visualize the distribution of articles. My strategy was to: -divide each group of words starting with the same letter into it's own array -if I had to reduce the number of volumes: -combine 2 adjacent letter arrays into a single array based on which 2 arrays have the smallest combined length -repeat this procedure until the desired number of volumes is achieved Notes: -This algorithm can result in poorly balanced distribution of volumes because it glues together adjacent volumes permanently. A more even distribution could be achieved if you could break a volume off after it had already been combined. -Certain number of volumes will result in really even distribution. 17 with the provided articles worked out well. -I think it would be interesting to split larger volumes as well. I think in some encyclopedias you'll find volumes with more common words split (eg. Ma - Me and Mi -Mz) My code could be much improved - quick and dirty. Well, maybe not so much quick, but dirty. Luke -- Posted via http://www.ruby-forum.com/.