Avatar of artemkorsakov

artemkorsakov's solution

to Pangram in the C# Track

Published at Jan 29 2019 · 0 comments
Instructions
Test suite
Solution

Note:

This exercise has changed since this solution was written.

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

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 Pangram.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

Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

PangramTest.cs

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

using Xunit;

public class PangramTest
{
    [Fact]
    public void Sentence_empty()
    {
        Assert.False(Pangram.IsPangram(""));
    }

    [Fact(Skip = "Remove to run test")]
    public void Recognizes_a_perfect_lower_case_pangram()
    {
        Assert.True(Pangram.IsPangram("abcdefghijklmnopqrstuvwxyz"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Pangram_with_only_lower_case()
    {
        Assert.True(Pangram.IsPangram("the quick brown fox jumps over the lazy dog"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Missing_character_x()
    {
        Assert.False(Pangram.IsPangram("a quick movement of the enemy will jeopardize five gunboats"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Another_missing_character_e_g_h()
    {
        Assert.False(Pangram.IsPangram("five boxing wizards jump quickly at it"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Pangram_with_underscores()
    {
        Assert.True(Pangram.IsPangram("the_quick_brown_fox_jumps_over_the_lazy_dog"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Pangram_with_numbers()
    {
        Assert.True(Pangram.IsPangram("the 1 quick brown fox jumps over the 2 lazy dogs"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Missing_letters_replaced_by_numbers()
    {
        Assert.False(Pangram.IsPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"));
    }

    [Fact(Skip = "Remove to run test")]
    public void Pangram_with_mixed_case_and_punctuation()
    {
        Assert.True(Pangram.IsPangram("\"Five quacking Zephyrs jolt my wax bed.\""));
    }

    [Fact(Skip = "Remove to run test")]
    public void Upper_and_lower_case_versions_of_the_same_character_should_not_be_counted_separately()
    {
        Assert.False(Pangram.IsPangram("the quick brown fox jumps over with lazy FX"));
    }
}
using System;
using System.Linq;
using System.Text.RegularExpressions;

public static class Pangram
{
    public static bool IsPangram(string input)
    {
        return Regex.Replace(input.ToLower(), "[^a-z]", "").ToCharArray().Distinct().Count() == 26;
    }
}

Community comments

Find this solution interesting? Ask the author a question to learn more.

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?
  • Are there new concepts here that you could read more about to improve your understanding?