Last active
October 21, 2022 08:15
-
-
Save savaged/0cbbc22866883f1e8b7552e61f0c7a80 to your computer and use it in GitHub Desktop.
Caesar Cipher in C# (with Linq)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (args?.Count() > 0) | |
Console.WriteLine(args[0].Select(c => | |
c switch | |
{ | |
>= 'a' and <= 'm' or >= 'A' and <= 'M' => (char)(c + 13), | |
>= 'n' and <= 'z' or >= 'N' and <= 'Z' => (char)(c - 13), | |
_ => c | |
} | |
).ToArray()); |
The Challenge
Caesar Cipher in the least procedural way (with extra points for the least number of semi-colons).
TDD
> Rot13 Test13!
> Grfg13!
> Rot13 Grfg13!
> Test13!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using top-level statements (see https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements) and Linq along with pattern matching (see https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)