Last active
          August 29, 2015 14:06 
        
      - 
      
- 
        Save hodzanassredin/c79c34ce02185cc092af to your computer and use it in GitHub Desktop. 
    bagofwords
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text.RegularExpressions; | |
| namespace ConsoleApplication4{ | |
| class Program{ | |
| static string text = @"Functional programming is like describing your problem to a | |
| mathematician. Imperative programming is like giving instructions to | |
| an idiot. | |
| -- arcus, #scheme on Freenode"; | |
| private static IEnumerable<string> BagOfWords() | |
| { | |
| return Regex.Split(text.ToLower(), @"\W+") | |
| .GroupBy(x => x) | |
| .GroupBy(x => x.Count()) | |
| .OrderByDescending(x => x.Key) | |
| .Select(x => String.Format("{0}:{1}", x.Key, String.Join(",", x.Select(y => y.Key)))); | |
| } | |
| static void Main(string[] args){ | |
| foreach (var str in BagOfWords()) | |
| { | |
| Console.WriteLine(str); | |
| } | |
| Console.ReadKey(); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment