Skip to content

Instantly share code, notes, and snippets.

@dylanbeattie
Last active February 2, 2022 12:15
Show Gist options
  • Save dylanbeattie/899766eee2ab086aa2d117c6b6805f29 to your computer and use it in GitHub Desktop.
Save dylanbeattie/899766eee2ab086aa2d117c6b6805f29 to your computer and use it in GitHub Desktop.
Pangram algorithms in C#
// 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);
}
}
@Ochuwa-sophie
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment