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.
Execute the tests with:
$ mix test
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!"
end
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
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
defmodule PangramTest do
use ExUnit.Case
# @tag :pending
test "empty sentence" do
refute Pangram.pangram?("")
end
@tag :pending
test "pangram with only lower case" do
assert Pangram.pangram?("the quick brown fox jumps over the lazy dog")
end
@tag :pending
test "missing character 'x'" do
refute Pangram.pangram?("a quick movement of the enemy will jeopardize five gunboats")
end
@tag :pending
test "another missing character 'x'" do
refute Pangram.pangram?("the quick brown fish jumps over the lazy dog")
end
@tag :pending
test "pangram with underscores" do
assert Pangram.pangram?("the_quick_brown_fox_jumps_over_the_lazy_dog")
end
@tag :pending
test "pangram with numbers" do
assert Pangram.pangram?("the 1 quick brown fox jumps over the 2 lazy dogs")
end
@tag :pending
test "missing letters replaced by numbers" do
refute Pangram.pangram?("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")
end
@tag :pending
test "pangram with mixed case and punctuation" do
assert Pangram.pangram?("Five quacking Zephyrs jolt my wax bed.")
end
@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.")
end
@tag :pending
test "pangram in alphabet other than ASCII" do
refute Pangram.pangram?(
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства."
)
end
end
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)
defmodule Pangram do
@doc """
Determines if a word or sentence is a pangram.
A pangram is a sentence using every letter of the alphabet at least once.
Returns a boolean.
## Examples
iex> Pangram.pangram?("the quick brown fox jumps over the lazy dog")
true
"""
@alphabet Enum.to_list(?a..?z)
@spec pangram?(String.t()) :: boolean
def pangram?(sentence) do
(@alphabet -- characters_in(sentence)) |> Enum.empty?()
end
def characters_in(sentence), do: to_charlist(String.downcase(sentence))
end
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.
Level up your programming skills with 3,450 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors. Exercism is 100% free forever.
Sign up Learn More
Community comments