Filkolev

Little John - using LINQ

May 21st, 2015
284
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class LittleJohn
  7. {
  8.     public static void Main()
  9.     {
  10.         StringBuilder sb = new StringBuilder();
  11.  
  12.         for (int i = 0; i < 4; i++)
  13.         {
  14.             sb.AppendFormat(" {0}", Console.ReadLine());
  15.         }
  16.  
  17.         const string ArrowPattern = @"(>>>----->>)|(>>----->)|(>----->)";
  18.  
  19.         Regex arrowMatcher = new Regex(ArrowPattern);
  20.  
  21.         var arrows = arrowMatcher.Matches(sb.ToString()).Cast<Match>();
  22.  
  23.         int largeArrowCount = arrows.Count(match => match.Groups[1].Value != string.Empty);
  24.         int mediumArrowCount = arrows.Count(match => match.Groups[2].Value != string.Empty);
  25.         int smallArrowCount = arrows.Count(match => match.Groups[3].Value != string.Empty);
  26.  
  27.         string numberAsString = string.Format(
  28.             "{0}{1}{2}",
  29.             smallArrowCount,
  30.             mediumArrowCount,
  31.             largeArrowCount);
  32.  
  33.         int number = int.Parse(numberAsString);
  34.  
  35.         string binaryNum = Convert.ToString(number, 2);
  36.  
  37.         string reversedBinaryNum = new string(binaryNum.Reverse().ToArray());
  38.  
  39.         string resultAsString = binaryNum + reversedBinaryNum;
  40.  
  41.         int result = Convert.ToInt32(resultAsString, 2);
  42.  
  43.         Console.WriteLine(result);
  44.     }
  45. }
RAW Paste Data