Date: 2013-06-20 10:50 pm (UTC)
From: [identity profile] 109.livejournal.com
13 - curly bracket alone does not count:

using System;
using System.IO;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		File.ReadAllText(args[0]).
			Split("all non-alpha characters here".ToCharArray()).
			GroupBy(x => x, (x, y) => new {word = x, count = y.Count()}).
			OrderBy(x => x.count).
			Reverse().
			Take(int.Parse(args[1])).
			ToList().
			ForEach(x => Console.WriteLine(x.word, "=", x.count));
	}
}
а если бы в IEnumerable был метод ForEach, то и 12. глубинный смысл отсуствия там оного меня угнетает.
Edited Date: 2013-06-20 10:53 pm (UTC)

Date: 2013-06-20 10:55 pm (UTC)
From: [identity profile] 109.livejournal.com
стормозил. надо OrderBy(x => -x.count), тогда Reverse не надо, ещё на линию меньше.

Date: 2013-06-21 07:55 pm (UTC)
From: [identity profile] inv2004.livejournal.com
Ещё A-Z в a-z забыли.

Profile

thedeemon: (Default)
Dmitry Popov

December 2025

S M T W T F S
 12 3456
789101112 13
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 28th, 2026 04:34 am
Powered by Dreamwidth Studios