ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# freddie2025's solution

## to Secret Handshake in the C# Track

Published at May 07 2019 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

There are 10 types of people in the world: Those who understand binary, and those who don't.

You and your fellow cohort of those in the "know" when it comes to binary decide to come up with a secret "handshake".

``````1 = wink
1000 = jump

10000 = Reverse the order of the operations in the secret handshake.
``````

Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.

Here's a couple of examples:

Given the input 3, the function would return the array ["wink", "double blink"] because 3 is 11 in binary.

Given the input 19, the function would return the array ["double blink", "wink"] because 19 is 10011 in binary. Notice that the addition of 16 (10000 in binary) has caused the array to be reversed.

## Running the tests

To run the tests, run the command `dotnet test` from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the `Skip` property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using `exercism submit SecretHandshake.cs`

## Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.

## Source

Bert, in Mary Poppins http://www.imdb.com/title/tt0058331/quotes/qt0437047

### SecretHandshakeTest.cs

``````// This file was auto-generated based on version 1.2.0 of the canonical data.

using Xunit;

public class SecretHandshakeTest
{
[Fact]
public void Wink_for_1()
{
Assert.Equal(new[] { "wink" }, SecretHandshake.Commands(1));
}

[Fact(Skip = "Remove to run test")]
{
Assert.Equal(new[] { "double blink" }, SecretHandshake.Commands(2));
}

[Fact(Skip = "Remove to run test")]
public void Close_your_eyes_for_100()
{
Assert.Equal(new[] { "close your eyes" }, SecretHandshake.Commands(4));
}

[Fact(Skip = "Remove to run test")]
public void Jump_for_1000()
{
Assert.Equal(new[] { "jump" }, SecretHandshake.Commands(8));
}

[Fact(Skip = "Remove to run test")]
public void Combine_two_actions()
{
Assert.Equal(new[] { "wink", "double blink" }, SecretHandshake.Commands(3));
}

[Fact(Skip = "Remove to run test")]
public void Reverse_two_actions()
{
Assert.Equal(new[] { "double blink", "wink" }, SecretHandshake.Commands(19));
}

[Fact(Skip = "Remove to run test")]
public void Reversing_one_action_gives_the_same_action()
{
Assert.Equal(new[] { "jump" }, SecretHandshake.Commands(24));
}

[Fact(Skip = "Remove to run test")]
public void Reversing_no_actions_still_gives_no_actions()
{
Assert.Empty(SecretHandshake.Commands(16));
}

[Fact(Skip = "Remove to run test")]
public void All_possible_actions()
{
}

[Fact(Skip = "Remove to run test")]
public void Reverse_all_possible_actions()
{
}

[Fact(Skip = "Remove to run test")]
public void Do_nothing_for_zero()
{
Assert.Empty(SecretHandshake.Commands(0));
}
}``````
``````ï»¿using System;
using System.Linq;

[FlagsAttribute]
public enum CommandAction
{
wink = 1,
close_your_eyes = 4,
jump= 8,
reverse = 16
}

public static class SecretHandshake
{
public static string[] Commands(int commandValue)
{
var commandActions = (CommandAction)commandValue;
bool reverse = commandActions.HasFlag(CommandAction.reverse);
var secretHandshake = commandActions.ToString().Replace(" ", "").Replace('_', ' ').Split(',');

return commandValue < 1 ? new string[] {} : reverse ? secretHandshake.Where(x => x != CommandAction.reverse.ToString()).Reverse().ToArray() : secretHandshake;
}
}``````

### What can you learn from this solution?

A huge amount can be learned from reading other peopleâ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

• What compromises have been made?