Sha256: adcdf4801afbdf5dbec1261c3aa9d11a302e52d771aa33c17ba89d999dc5f7f2

Contents?: true

Size: 1.51 KB

Versions: 28

Compression:

Stored size: 1.51 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 verseNumber)
    {
        return Recite(verseNumber, verseNumber);
    }
    
    public static string Recite(int startVerse, int endVerse)
    {
        var numberOfVerses = endVerse - startVerse + 1;
        return string.Join("\n", Enumerable.Range(startVerse, numberOfVerses).Select(Verse));
    }

    private static string Verse(int number)
    {
        return string.Join(" ", 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

28 entries across 28 versions & 1 rubygems

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