diff --git a/config.json b/config.json index da7dc2736..dd2f6dbbc 100644 --- a/config.json +++ b/config.json @@ -68,6 +68,15 @@ "Maybe" ] }, + { + "uuid": "6eba4eac-6665-4ad6-ac21-3651a11ab4b4", + "slug": "isogram", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + ] + }, { "uuid": "85d77b8e-9b87-4d02-9fba-81f843bd66f1", "slug": "rna-transcription", diff --git a/exercises/isogram/README.md b/exercises/isogram/README.md new file mode 100644 index 000000000..49384d67e --- /dev/null +++ b/exercises/isogram/README.md @@ -0,0 +1,73 @@ +# Isogram + +Determine if a word or phrase is an isogram. + +An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter. + +Examples of isograms: + +- lumberjacks +- background +- downstream + +The word *isograms*, however, is not an isogram, because the s repeats. + + +## Getting Started + +For installation and learning resources, refer to the +[exercism help page](http://exercism.io/languages/haskell). + +## Running the tests + +To run the test suite, execute the following command: + +```bash +stack test +``` + +#### If you get an error message like this... + +``` +No .cabal file found in directory +``` + +You are probably running an old stack version and need +to upgrade it. + +#### Otherwise, if you get an error message like this... + +``` +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: + +```bash +stack setup +``` + +## Running *GHCi* + +If you want to play with your solution in GHCi, just run the command: + +```bash +stack ghci +``` + +## Feedback, Issues, Pull Requests + +The [exercism/haskell](https://github.com/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! + +## Source + +Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/isogram/examples/success-standard/package.yaml b/exercises/isogram/examples/success-standard/package.yaml new file mode 100644 index 000000000..8ba83ebe9 --- /dev/null +++ b/exercises/isogram/examples/success-standard/package.yaml @@ -0,0 +1,16 @@ +name: isogram + +dependencies: + - base + +library: + exposed-modules: Isogram + source-dirs: src + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - isogram + - hspec diff --git a/exercises/isogram/examples/success-standard/src/Isogram.hs b/exercises/isogram/examples/success-standard/src/Isogram.hs new file mode 100644 index 000000000..40cbaece5 --- /dev/null +++ b/exercises/isogram/examples/success-standard/src/Isogram.hs @@ -0,0 +1,7 @@ +module Isogram (isIsogram) where + +import Data.Char (toLower, isLetter) +import Data.List (sort, group) + +isIsogram :: String -> Bool +isIsogram = all ((1==) . length) . group . sort . filter isLetter . map toLower diff --git a/exercises/isogram/package.yaml b/exercises/isogram/package.yaml new file mode 100644 index 000000000..15b24720c --- /dev/null +++ b/exercises/isogram/package.yaml @@ -0,0 +1,20 @@ +name: isogram +version: 1.1.0.1 + +dependencies: + - base + +library: + exposed-modules: Isogram + source-dirs: src + dependencies: + # - foo # List here the packages you + # - bar # want to use in your solution. + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - isogram + - hspec diff --git a/exercises/isogram/src/Isogram.hs b/exercises/isogram/src/Isogram.hs new file mode 100644 index 000000000..9d5700607 --- /dev/null +++ b/exercises/isogram/src/Isogram.hs @@ -0,0 +1,4 @@ +module Isogram (isIsogram) where + +isIsogram :: String -> Bool +isIsogram = error "You need to implement this function!" diff --git a/exercises/isogram/stack.yaml b/exercises/isogram/stack.yaml new file mode 100644 index 000000000..10da6ea9e --- /dev/null +++ b/exercises/isogram/stack.yaml @@ -0,0 +1 @@ +resolver: lts-8.21 diff --git a/exercises/isogram/test/Tests.hs b/exercises/isogram/test/Tests.hs new file mode 100644 index 000000000..50455734c --- /dev/null +++ b/exercises/isogram/test/Tests.hs @@ -0,0 +1,63 @@ +{-# LANGUAGE RecordWildCards #-} + +import Data.Foldable (for_) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) + +import Isogram (isIsogram) + +main :: IO () +main = hspecWith defaultConfig {configFastFail = True} specs + +specs :: Spec +specs = describe "isIsogram" $ for_ cases test + where + + test Case{..} = it description assertion + where + assertion = isIsogram input `shouldBe` expected + + +data Case = Case { description :: String + , input :: String + , expected :: Bool + } + +cases :: [Case] +cases = [ Case { description = "empty string" + , input = "" + , expected = True + } + , Case { description = "isogram with only lower case characters" + , input = "isogram" + , expected = True + } + , Case { description = "word with one duplicated character" + , input = "eleven" + , expected = False + } + , Case { description = "longest reported english isogram" + , input = "subdermatoglyphic" + , expected = True + } + , Case { description = "word with duplicated character in mixed case" + , input = "Alphabet" + , expected = False + } + , Case { description = "hypothetical isogrammic word with hyphen" + , input = "thumbscrew-japingly" + , expected = True + } + , Case { description = "isogram with duplicated non letter character" + , input = "Hjelmqvist-Gryb-Zock-Pfund-Wax" + , expected = True + } + , Case { description = "made-up name that is an isogram" + , input = "Emily Jung Schwartzkopf" + , expected = True + } + , Case { description = "duplicated character in the middle" + , input = "accentor" + , expected = False + } + ]