Sha256: 95c075abeda0257fb8d60668982ccb6fad4e51833d171cbef13130eaf386fae7

Contents?: true

Size: 996 Bytes

Versions: 228

Compression:

Stored size: 996 Bytes

Contents

using System;
using System.Linq;

public static class Diamond
{
    public static string Make(char target)
    {
        var letters = GetLetters(target);
        var diamondLetters = letters.Concat(letters.Reverse().Skip(1)).ToArray();

        return string.Join("\n", diamondLetters.Select(diamondLetter => MakeLine(letters.Length, diamondLetter)));
    }

    private static Tuple<char, int>[] GetLetters(char target) =>
        Enumerable
            .Range('A', target - 'A' + 1)
            .Select((c, i) => Tuple.Create((char)c, i))
            .ToArray();

    private static string MakeLine(int letterCount, Tuple<char, int> rowLetter)
    {
        var letter = rowLetter.Item1;
        var row = rowLetter.Item2;
        var outerSpaces = "".PadRight(letterCount - row - 1);
        var innerSpaces = "".PadRight(row == 0 ? 0 : row*2 - 1);

        return letter == 'A' ? $"{outerSpaces}{letter}{outerSpaces}" : $"{outerSpaces}{letter}{innerSpaces}{letter}{outerSpaces}";
    }
}

Version data entries

228 entries across 228 versions & 1 rubygems

Version Path
trackler-2.2.1.10 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.9 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.8 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.7 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.6 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.5 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.4 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.3 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.2 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.1 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.1.0 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.6 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.5 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.4 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.3 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.2 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.1 tracks/csharp/exercises/diamond/Example.cs
trackler-2.2.0.0 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.55 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.54 tracks/csharp/exercises/diamond/Example.cs