Sha256: 213949961b7d9bdbbb272a96af06dbc3135985639db5f67f05cd75f0a8ba7b34

Contents?: true

Size: 919 Bytes

Versions: 396

Compression:

Stored size: 919 Bytes

Contents

using System.Collections.Generic;
using System.Linq;

public class SecretHandshake
{
    private static readonly Dictionary<int, string> CommandValues = new Dictionary<int, string>
        {
            { 1, "wink" },
            { 2, "double blink" },
            { 4, "close your eyes" },
            { 8, "jump" }
        };

    public static string[] Commands(int commandValue)
    {
        var commands = new List<string>();
        foreach (var value in CommandValues.OrderBy(x => x.Key))
        {
            if ((commandValue & value.Key) != 0)
            {
                commands.Add(value.Value);
            }
        }

        if (ShouldReverse(commandValue))
        {
            return commands.AsEnumerable().Reverse().ToArray();
        }
        return commands.ToArray();
    }

    private static bool ShouldReverse(int commandValue)
    {
        return (commandValue & 16) != 0;
    }
}

Version data entries

396 entries across 396 versions & 1 rubygems

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