Exercism v3 launches on Sept 1st 2021. Learn more! 🚀🚀🚀
Avatar of thekeele

thekeele's solution

to Pangram in the Elixir Track

Published at May 24 2019 · 0 comments
Test suite


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 tests

Execute the tests with:

$ elixir pangram_test.exs

Pending tests

In the test suites, all but the first test have been skipped.

Once you get a test passing, you can unskip the next one by commenting out the relevant @tag :pending with a # symbol.

For example:

# @tag :pending
test "shouting" do
  assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"

Or, you can enable all the tests by commenting out the ExUnit.configure line in the test suite.

# ExUnit.configure exclude: :pending, trace: true

If you're stuck on something, it may help to look at some of the available resources out there where answers might be found.


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.


if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("pangram.exs", __DIR__)

ExUnit.configure(exclude: :pending, trace: true)

defmodule PangramTest do
  use ExUnit.Case

  # @tag :pending
  test "empty sentence" do
    refute Pangram.pangram?("")

  @tag :pending
  test "pangram with only lower case" do
    assert Pangram.pangram?("the quick brown fox jumps over the lazy dog")

  @tag :pending
  test "missing character 'x'" do
    refute Pangram.pangram?("a quick movement of the enemy will jeopardize five gunboats")

  @tag :pending
  test "another missing character 'x'" do
    refute Pangram.pangram?("the quick brown fish jumps over the lazy dog")

  @tag :pending
  test "pangram with underscores" do
    assert Pangram.pangram?("the_quick_brown_fox_jumps_over_the_lazy_dog")

  @tag :pending
  test "pangram with numbers" do
    assert Pangram.pangram?("the 1 quick brown fox jumps over the 2 lazy dogs")

  @tag :pending
  test "missing letters replaced by numbers" do
    refute Pangram.pangram?("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")

  @tag :pending
  test "pangram with mixed case and punctuation" do
    assert Pangram.pangram?("Five quacking Zephyrs jolt my wax bed.")

  @tag :pending
  test "pangram with non ascii characters" do
    assert Pangram.pangram?("Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.")

  @tag :pending
  test "pangram in alphabet other than ASCII" do
    refute Pangram.pangram?(
             "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства."
defmodule Pangram do

  @alphabet Enum.map(?a..?z, &<<&1::utf8>>)

  @spec pangram?(String.t()) :: boolean
  def pangram?(""), do: false
  def pangram?(sentence) do
    pangram =
      |> String.codepoints()
      |> Enum.reduce([], fn letter, pangram ->
        letter = String.downcase(letter)
        if letter in @alphabet and letter not in pangram, do: [letter | pangram], else: pangram
      |> Enum.sort()

    pangram === @alphabet

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?