Advertisement
NPSF3000

Roman Numerals?

Apr 2nd, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. //  After someone demonstrating that haskal can convert roman numerals to decimal in 1LOC
  2. //  I thought I'd show that stupidity isn't limited to that language alone.
  3. //  http://thedailywtf.com/Articles/Roman-Enumeration.aspx
  4.  
  5. using System;
  6. using System.Linq;
  7.  
  8. namespace RomanNumbers
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             while (true)
  15.             {
  16.                 (from fluff in " "
  17.                  let n = (from c in Console.ReadLine().ToUpper()
  18.                           where "IVXLCDM".Contains(c)
  19.                           select c == 'I' ? 1 : c == 'V' ? 5 : c == 'X' ? 10 : c == 'L' ? 50 : c == 'C' ? 100 : c == 'D' ? 500 : 1000).ToList()
  20.                  let r = from i in Enumerable.Range(0, n.Count)
  21.                          let l = i > 0 && n[i] > n[i - 1] ? -n[i - 1] * 2 : 0
  22.                          select n[i] + l
  23.                  select r.Sum()).ToList().ForEach(Console.WriteLine);
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement