-
-
Save dylanbeattie/899766eee2ab086aa2d117c6b6805f29 to your computer and use it in GitHub Desktop.
Pangram algorithms in C#
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
// See https://aka.ms/new-console-template for more information | |
var input = "THE quick BROWN foX Jumps over the lazy cat"; | |
var isPangram = Pangram.IsPangram(input); | |
Console.WriteLine(isPangram ? "Yes!" : "No"); | |
public class Pangram { | |
const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
public static bool IsPangram(string text) { | |
text = text.ToLower(); | |
var result = alphabet.All(letter => { | |
Console.WriteLine($"Checking whether text contains '{letter}..."); | |
var textContainsLetter = text.Contains(letter); | |
if (textContainsLetter) { | |
Console.WriteLine("Yes, it does! Checking the next letter..."); | |
} else { | |
Console.WriteLine($"No, the letter '{letter}' is NOT in the text, so this is not a pangram."); | |
} | |
return textContainsLetter; | |
}); | |
return result; | |
} | |
} | |
public class PangramVersion2 { | |
const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
public static bool IsPangram(string text) { | |
text = text.ToLower(); | |
var result = alphabet.All(letter => text.Contains(letter)); | |
return result; | |
} | |
} | |
public class PangramVersion3 { | |
const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
public static bool IsPangram(string text) { | |
text = text.ToLower(); | |
return alphabet.All(text.Contains); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.