Sha256: 3dedbd76b3b8e91903b66bcdfdbb91471cc5309fd54738b1eec42568428fe874

Contents?: true

Size: 1.16 KB

Versions: 183

Compression:

Stored size: 1.16 KB

Contents

module pangram;

import std.uni : toLower;

bool isPangram(string str)
{
    bool[dchar] letters;
    foreach (char letter; str)
    {
        auto lower = toLower(letter);
        if (lower >= 'a' && lower <= 'z')
        {
            letters[lower] = true;
        }
    }
    return letters.length == 26;
}

unittest
{
    assert(!isPangram(""));
    assert(isPangram("the quick brown fox jumps over the lazy dog"));
    // missing x
    assert(!isPangram("a quick movement of the enemy will jeopardize five gunboats"));
    assert(!isPangram("the quick brown fish jumps over the lazy dog"));
    // test underscores
    assert(isPangram("the_quick_brown_fox_jumps_over_the_lazy_dog"));
    // test pangram with numbers
    assert(isPangram("the 1 quick brown fox jumps over the 2 lazy dogs"));
    // test missing letters replaced by numbers
    assert(!isPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"));
    // test pangram with mixed case and punctuation
    assert(isPangram("\"Five quacking Zephyrs jolt my wax bed\""));
    // pangram with non-ascii characters
    assert(isPangram("Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich"));
}

void main() {}

Version data entries

183 entries across 183 versions & 1 rubygems

Version Path
trackler-2.1.0.27 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.26 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.25 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.24 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.23 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.22 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.21 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.20 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.19 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.18 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.17 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.16 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.15 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.14 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.13 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.12 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.11 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.10 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.9 tracks/dlang/exercises/pangram/pangram_example.d
trackler-2.1.0.8 tracks/dlang/exercises/pangram/pangram_example.d