Sha256: 5c48a5537be11476280bbb4638c6612a37281c664b3af4f7b8ab3cad9bf4f830

Contents?: true

Size: 1.4 KB

Versions: 87

Compression:

Stored size: 1.4 KB

Contents

using System.Linq;

public static class House
{
    private static readonly string[] Subjects =
    {
        "house that Jack built",
        "malt",
        "rat",
        "cat",
        "dog",
        "cow with the crumpled horn",
        "maiden all forlorn",
        "man all tattered and torn",
        "priest all shaven and shorn",
        "rooster that crowed in the morn",
        "farmer sowing his corn",
        "horse and the hound and the horn"
    };

    private static readonly string[] Verbs =
    {
        "lay in",
        "ate",
        "killed",
        "worried",
        "tossed",
        "milked",
        "kissed",
        "married",
        "woke",
        "kept",
        "belonged to",
        ""
    };
    
    public static string Recite(int startVerse, int endVerse)
    {
        var numberOfVerses = endVerse - startVerse + 1;
        return string.Join("\n\n", Enumerable.Range(startVerse, numberOfVerses).Select(Verse));
    }

    private static string Verse(int number)
    {
        return string.Join("\n", Enumerable.Range(1, number).Reverse().Select(index => Line(number, index)));
    }

    private static string Line(int number, int index)
    {
        var subject = Subjects[index - 1];
        var verb = Verbs[index - 1];
        var ending = index == 1 ? "." : "";

        return index == number ? $"This is the {subject}{ending}" : $"that {verb} the {subject}{ending}";
    }
}

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
trackler-2.2.1.151 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.150 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.149 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.148 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.147 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.146 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.145 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.144 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.143 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.142 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.141 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.140 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.139 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.138 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.137 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.136 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.135 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.134 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.133 tracks/csharp/exercises/house/Example.cs
trackler-2.2.1.132 tracks/csharp/exercises/house/Example.cs