🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of bitblight

bitblight's solution

to Pangram in the Erlang Track

Published at May 15 2021 · 0 comments
Test suite

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 tests

In order to run the tests, issue the following command from the exercise directory:

For running the tests provided, rebar3 is used as it is the official build and dependency management tool for erlang now. Please refer to the tracks installation instructions on how to do that.

In order to run the tests, you can issue the following command from the exercise directory.

$ rebar3 eunit


For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.


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.


%% Generated with 'testgen v0.2.0'
%% Revision 1 of the exercises generator was used
%% https://github.com/exercism/problem-specifications/raw/42dd0cea20498fd544b152c4e2c0a419bb7e266a/exercises/pangram/canonical-data.json
%% This file is automatically generated from the exercises canonical data.



'1_empty_sentence_test_'() ->
    {"empty sentence", ?_assertNot(pangram:is_pangram([]))}.

'2_perfect_lower_case_test_'() ->
    {"perfect lower case",

'3_only_lower_case_test_'() ->
    {"only lower case",
     ?_assert(pangram:is_pangram("the quick brown fox jumps over the lazy "

'4_missing_the_letter_x_test_'() ->
    {"missing the letter 'x'",
     ?_assertNot(pangram:is_pangram("a quick movement of the enemy will jeopardize "
				    "five gunboats"))}.

'5_missing_the_letter_h_test_'() ->
    {"missing the letter 'h'",
     ?_assertNot(pangram:is_pangram("five boxing wizards jump quickly at it"))}.

'6_with_underscores_test_'() ->
    {"with underscores",

'7_with_numbers_test_'() ->
    {"with numbers",
     ?_assert(pangram:is_pangram("the 1 quick brown fox jumps over the "
				 "2 lazy dogs"))}.

'8_missing_letters_replaced_by_numbers_test_'() ->
    {"missing letters replaced by numbers",
     ?_assertNot(pangram:is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy "

'9_mixed_case_and_punctuation_test_'() ->
    {"mixed case and punctuation",
     ?_assert(pangram:is_pangram("\"Five quacking Zephyrs jolt my wax "

'10_case_insensitive_test_'() ->
    {"case insensitive",
     ?_assertNot(pangram:is_pangram("the quick brown fox jumps over with "
				    "lazy FX"))}.


ascii_bitset(CharacterSet, Mask, BitSet) when
        (CharacterSet =:= []); (Mask > 0 and (BitSet band Mask =:= Mask)) ->

ascii_bitset([Character|CharacterSet], Mask, BitSet) ->
    ascii_bitset(CharacterSet, Mask, BitSet bor (1 bsl Character)).

ascii_bitset(CharacterSet, Mask) ->
    ascii_bitset(CharacterSet, Mask, 0).

ascii_bitset(CharacterSet) ->
    ascii_bitset(CharacterSet, 0).

contains_all_characters(Sentence, CharacterSet) ->
    CharacterMask = ascii_bitset(CharacterSet),
    ascii_bitset(Sentence, CharacterMask) band CharacterMask =:= CharacterMask.

is_pangram(Sentence) ->
        string:lowercase(Sentence), "abcdefghijklmnopqrstuvwxyz"

Community comments

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

bitblight's Reflection

I learnt a bit about Erlang's guard syntax and integers. My first attempt was more verbose and rigidly constrained to alphabetical characters. Generalising bit set generation to any ordinal shortened it and made it more flexible, taking advantage of Erlang's bignum support.