title: Build an ASCII chart of the most commonly used words in a given text
body: <h2><strong>The challenge:</strong></h2>
  
  <p>Build an ASCII chart of the most commonly used words in a given text.</p>
  
  <p><strong>The rules:</strong></p>
  
  <ul>
  <li>Only accept <code>a-z</code> and <code>A-Z</code> (alphabetic characters) as part of a word. </li>
  <li>Ignore casing (<code>She</code> == <code>she</code> for our purpose). </li>
  <li>Ignore the following words (quite arbitary, I know): <code>the, and, of, to, a, i, it, in, or, is</code></li>
  <li><p>Clarification: considering <code>don't</code>: this would be taken as 2 different 'words' in the ranges <code>a-z</code> and <code>A-Z</code>: (<code>don</code> and <code>t</code>). </p></li>
  <li><p><strong>Optionally</strong> (it's too late to be formally changing the specifications now) you <strong>may</strong> choose to drop all single-letter 'words' (this could potentially make for a shortening of the ignore list too).</p></li>
  </ul>
  
  <p>Parse a given <code>text</code> (read a file specified via command line arguments or piped in; presume <code>us-ascii</code>) and build us a <code>word frequency chart</code> with the following characteristics: </p>
  
  <ul>
  <li>Display the chart (also see the example below) for the 22 most common words (ordered by descending frequency).</li>
  <li>The bar <code>width</code> represents the number of occurences (frequency) of the word (proportionally). Append one space and print the word.</li>
  <li>Make sure these bars (plus space-word-space) always <em>fit</em>: <code>bar</code> + <code>[space]</code> + <code>word</code> + <code>[space]</code> should be always &lt;= <code>80</code> characters (make sure you account for possible differing bar and word lengths: e.g.: the second most common word could be a lot longer then the first while not differing so much in frequency). <em>Maximize</em> bar width within these constraints and scale the bars appropriately (according to the frequencies they represent).</li>
  </ul>
  
  <p><strong>An example:</strong></p>
  
  <p>The text for the example <a href="http://www.gutenberg.org/files/11/11.txt" rel="nofollow noreferrer">can be found here</a> (<em>Alice's Adventures in Wonderland, by Lewis Carroll</em>).</p>
  
  <p>This specific text would yield the following chart:</p>
  
  <pre>
   _________________________________________________________________________
  |_________________________________________________________________________| she 
  |_______________________________________________________________| you 
  |____________________________________________________________| said 
  |____________________________________________________| alice 
  |______________________________________________| was 
  |__________________________________________| that 
  |___________________________________| as 
  |_______________________________| her 
  |____________________________| with 
  |____________________________| at 
  |___________________________| s 
  |___________________________| t 
  |_________________________| on 
  |_________________________| all 
  |______________________| this 
  |______________________| for 
  |______________________| had 
  |_____________________| but 
  |____________________| be 
  |____________________| not 
  |___________________| they 
  |__________________| so 
  
  
  </pre>
  
  <p>For your information: these are the frequencies the above chart is built upon:</p>
  
  <pre>
  [('she', 553), ('you', 481), ('said', 462), ('alice', 403), ('was', 358), ('that
  ', 330), ('as', 274), ('her', 248), ('with', 227), ('at', 227), ('s', 219), ('t'
  , 218), ('on', 204), ('all', 200), ('this', 181), ('for', 179), ('had', 178), ('
  but', 175), ('be', 167), ('not', 166), ('they', 155), ('so', 152)]
  </pre>
  
  <p><strong>A second example (to check if you implemented the complete spec):</strong>
  Replace every occurence of <code>you</code> in the linked <em>Alice in Wonderland</em> file with <code>superlongstringstring</code>:</p>
  
  <pre>
   ________________________________________________________________
  |________________________________________________________________| she 
  |_______________________________________________________| superlongstringstring 
  |_____________________________________________________| said 
  |______________________________________________| alice 
  |________________________________________| was 
  |_____________________________________| that 
  |______________________________| as 
  |___________________________| her 
  |_________________________| with 
  |_________________________| at 
  |________________________| s 
  |________________________| t 
  |______________________| on 
  |_____________________| all 
  |___________________| this 
  |___________________| for 
  |___________________| had 
  |__________________| but 
  |_________________| be 
  |_________________| not 
  |________________| they 
  |________________| so 
  </pre>
  
  <p><strong>The winner:</strong></p>
  
  <p>Shortest solution (by character count, per language). Have fun!</p>
  
  <hr>
  
  <p><strong>Edit</strong>: Table summarizing the results so far (2012-02-15) (originally added by user Nas Banov):</p>
  
  <pre>
  Language          Relaxed  Strict
  =========         =======  ======
  GolfScript          130     143
  Perl                        185
  Windows PowerShell  148     199
  Mathematica                 199
  Ruby                185     205
  Unix Toolchain      194     228
  Python              183     243
  Clojure                     282
  Scala                       311
  Haskell                     333
  Awk                         336
  R                   298
  Javascript          304     354
  Groovy              321
  Matlab                      404
  C#                          422
  Smalltalk           386
  PHP                 450
  F#                          452
  TSQL                483     507
  </pre>
  
  <p>The numbers represent the length of the shortest solution in a specific language. "Strict" refers to a solution that implements the spec completely (draws <code>|____|</code> bars, closes the first bar on top with a <code>____</code> line, accounts for the possibility of long words with high frequency etc). "Relaxed" means some liberties were taken to shorten to solution. </p>
  
  <p>Only solutions shorter then 500 characters are included. The list of languages is sorted by the length of the 'strict' solution. 'Unix Toolchain' is used to signify various solutions that use traditional *nix shell <em>plus</em> a mix of tools (like grep, tr, sort, uniq,  head, perl, awk).</p>