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.
For installation and learning resources, refer to the exercism help page.
To run the test suite, execute the following command:
stack test
No .cabal file found in directory
You are probably running an old stack version and need to upgrade it.
No compiler found, expected minor version match with...
Try running "stack setup" to install the correct GHC...
Just do as it says and it will download and install the correct compiler version:
stack setup
If you want to play with your solution in GHCi, just run the command:
stack ghci
The exercism/haskell repository on GitHub is the home for all of the Haskell exercises.
If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue. We'll do our best to help you!
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.
{-# LANGUAGE RecordWildCards #-}
import Data.Foldable (for_)
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)
import Pangram (isPangram)
main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs
specs :: Spec
specs = describe "isPangram" $ for_ cases test
where
test Case{..} = it description $ isPangram input `shouldBe` expected
data Case = Case { description :: String
, input :: String
, expected :: Bool
}
cases :: [Case]
cases = [ Case { description = "sentence empty"
, input = ""
, expected = False
}
, Case { description = "recognizes a perfect lower case pangram"
, input = "abcdefghijklmnopqrstuvwxyz"
, expected = True
}
, Case { description = "pangram with only lower case"
, input = "the quick brown fox jumps over the lazy dog"
, expected = True
}
, Case { description = "missing character 'x'"
, input = "a quick movement of the enemy will jeopardize five gunboats"
, expected = False
}
, Case { description = "another missing character, e.g. 'h'"
, input = "five boxing wizards jump quickly at it"
, expected = False
}
, Case { description = "pangram with underscores"
, input = "the_quick_brown_fox_jumps_over_the_lazy_dog"
, expected = True
}
, Case { description = "pangram with numbers"
, input = "the 1 quick brown fox jumps over the 2 lazy dogs"
, expected = True
}
, Case { description = "missing letters replaced by numbers"
, input = "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"
, expected = False
}
, Case { description = "pangram with mixed case and punctuation"
, input = "\"Five quacking Zephyrs jolt my wax bed.\""
, expected = True
}
, Case { description = "upper and lower case versions of the same character should not be counted separately"
, input = "the quick brown fox jumps over with lazy FX"
, expected = False
}
]
module Pangram (isPangram) where
import Data.Char (toLower)
-- make string all lowercase
toLower' :: String -> String
toLower' s = [toLower c | c <- s]
-- check for membership of each lowercase letter in text
isPangram :: String -> Bool
isPangram text = all (`elem` toLower' text) ['a'..'z']
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,449 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