Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created October 24, 2020 19:00
Show Gist options
  • Save bkyrlach/6496b69d36fbce28a43e58038349a570 to your computer and use it in GitHub Desktop.
Save bkyrlach/6496b69d36fbce28a43e58038349a570 to your computer and use it in GitHub Desktop.
module Pangram where
import Data.Set (Set)
import Data.Set as Set
import Data.Char (toLower, isLetter)
import Data.List as List
isPangram :: [Char] -> Bool
isPangram s = 26 == (Set.size $ Set.fromList $ fmap toLower (List.filter isLetter s))
@bkyrlach
Copy link
Author

Here's another way to do it.

isPangram2 :: [Char] -> Bool
isPangram2 = (== 26) . snd . List.foldl countChanges ('-', 0) . List.sort . fmap toLower . List.filter isLetter

countChanges :: (Eq p) => (p, Int) -> p -> (p, Int)
countChanges (p, n) c = if (p == c) then (p, n) else (c, n+1)

@bkyrlach
Copy link
Author

combinePredicates :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
combinePredicates f g = \a -> (f a) && (g a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment