Sha256: 2b5bef081d54937d8288ee9056f7d45969063e5e3fe98f8567aa6ba9c67b2954

Contents?: true

Size: 811 Bytes

Versions: 396

Compression:

Stored size: 811 Bytes

Contents

using System.Collections.Generic;
using System.Text;

public static class RomanNumeralExtension
{
    private static readonly Dictionary<int, string> ArabicToRomanConversions = new Dictionary<int, string>
        {
            { 1000, "M" }, { 900, "CM" }, { 500, "D" }, { 400, "CD" }, { 100, "C" }, { 90, "XC" }, { 50, "L" },
            { 40, "XL" }, { 10, "X" }, { 9, "IX" }, { 5, "V" }, { 4, "IV" }, { 1, "I" }
        };

    public static string ToRoman(this int value)
    {
        var result = new StringBuilder();
        foreach (var conversion in ArabicToRomanConversions)
        {
            while (value / conversion.Key > 0)
            {
                value -= conversion.Key;
                result.Append(conversion.Value);
            }
        }
        return result.ToString();
    }
}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.179 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.178 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.177 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.176 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.175 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.174 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.173 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.172 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.171 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.170 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.169 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.167 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.166 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.165 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.164 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.163 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.162 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.161 tracks/csharp/exercises/roman-numerals/Example.cs
trackler-2.2.1.160 tracks/csharp/exercises/roman-numerals/Example.cs