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.1.0.32 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.31 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.30 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.29 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.28 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.27 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.26 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.25 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.24 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.23 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.22 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.21 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.20 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.19 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.18 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.17 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.16 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.15 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.14 tracks/csharp/exercises/diamond/Example.cs
trackler-2.1.0.13 tracks/csharp/exercises/diamond/Example.cs