From 857bc67953c5868f21306eca9bf9e432154b9dbc Mon Sep 17 00:00:00 2001 From: Average-user Date: Wed, 20 Sep 2017 02:20:52 -0300 Subject: [PATCH 1/8] adding isogram --- config.json | 10 +++ exercises/isogram/README.md | 72 +++++++++++++++++++ .../examples/success-standard/package.yaml | 16 +++++ .../examples/success-standard/src/Isogram.hs | 8 +++ exercises/isogram/package.yaml | 20 ++++++ exercises/isogram/src/Isogram.hs | 6 ++ exercises/isogram/stack.yaml | 1 + exercises/isogram/test/Tests.hs | 64 +++++++++++++++++ 8 files changed, 197 insertions(+) create mode 100644 exercises/isogram/README.md create mode 100644 exercises/isogram/examples/success-standard/package.yaml create mode 100644 exercises/isogram/examples/success-standard/src/Isogram.hs create mode 100644 exercises/isogram/package.yaml create mode 100644 exercises/isogram/src/Isogram.hs create mode 100644 exercises/isogram/stack.yaml create mode 100644 exercises/isogram/test/Tests.hs diff --git a/config.json b/config.json index da7dc2736..39fa3b4a1 100644 --- a/config.json +++ b/config.json @@ -68,6 +68,16 @@ "Maybe" ] }, + { + "uuid": "6eba4eac-6665-4ad6-ac21-3651a11ab4b4", + "slug": "isogram", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "Data.Char" + ] + }, { "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..29fb61c3e --- /dev/null +++ b/exercises/isogram/README.md @@ -0,0 +1,72 @@ +# 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 + +see more at [wikipedia page of isograms]("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..0c40c4ed5 --- /dev/null +++ b/exercises/isogram/examples/success-standard/src/Isogram.hs @@ -0,0 +1,8 @@ +module Isogram (isIsogram) where + +import Data.Char (isLetter, toLower) + +isIsogram :: String -> Bool +isIsogram = fn . map toLower + where fn [] = True + fn (x:xs) = if isLetter x && x `elem` xs then False else fn xs diff --git a/exercises/isogram/package.yaml b/exercises/isogram/package.yaml new file mode 100644 index 000000000..1f4920726 --- /dev/null +++ b/exercises/isogram/package.yaml @@ -0,0 +1,20 @@ +name: isogram +version: 1.1.0 + +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..4d5aa17b4 --- /dev/null +++ b/exercises/isogram/src/Isogram.hs @@ -0,0 +1,6 @@ +module Isogram (isIsogram) where + +import Data.Char + +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..2d82eebf4 --- /dev/null +++ b/exercises/isogram/test/Tests.hs @@ -0,0 +1,64 @@ +{-# OPTIONS_GHC -fno-warn-type-defaults #-} +{-# 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 + } + ] From ac9dd461bbdd0b99c4d0cea142a600bfa9d22230 Mon Sep 17 00:00:00 2001 From: Average-user Date: Wed, 20 Sep 2017 02:26:53 -0300 Subject: [PATCH 2/8] fix to isogram example --- exercises/isogram/examples/success-standard/src/Isogram.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/isogram/examples/success-standard/src/Isogram.hs b/exercises/isogram/examples/success-standard/src/Isogram.hs index 0c40c4ed5..f7c8daea2 100644 --- a/exercises/isogram/examples/success-standard/src/Isogram.hs +++ b/exercises/isogram/examples/success-standard/src/Isogram.hs @@ -5,4 +5,4 @@ import Data.Char (isLetter, toLower) isIsogram :: String -> Bool isIsogram = fn . map toLower where fn [] = True - fn (x:xs) = if isLetter x && x `elem` xs then False else fn xs + fn (x:xs) = not (isLetter x && x `elem` xs) && fn xs From ebcd98e6f5d1f6a2d8a33812c3c90efbda2503f3 Mon Sep 17 00:00:00 2001 From: Average-user Date: Wed, 20 Sep 2017 12:46:35 -0300 Subject: [PATCH 3/8] isogram:some corrections --- exercises/isogram/package.yaml | 2 +- exercises/isogram/src/Isogram.hs | 1 - exercises/isogram/test/Tests.hs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/exercises/isogram/package.yaml b/exercises/isogram/package.yaml index 1f4920726..15b24720c 100644 --- a/exercises/isogram/package.yaml +++ b/exercises/isogram/package.yaml @@ -1,5 +1,5 @@ name: isogram -version: 1.1.0 +version: 1.1.0.1 dependencies: - base diff --git a/exercises/isogram/src/Isogram.hs b/exercises/isogram/src/Isogram.hs index 4d5aa17b4..9da765bcf 100644 --- a/exercises/isogram/src/Isogram.hs +++ b/exercises/isogram/src/Isogram.hs @@ -1,6 +1,5 @@ module Isogram (isIsogram) where -import Data.Char isIsogram :: String -> Bool isIsogram = error "You need to implement this function!" diff --git a/exercises/isogram/test/Tests.hs b/exercises/isogram/test/Tests.hs index 2d82eebf4..a6811011c 100644 --- a/exercises/isogram/test/Tests.hs +++ b/exercises/isogram/test/Tests.hs @@ -1,4 +1,3 @@ -{-# OPTIONS_GHC -fno-warn-type-defaults #-} {-# LANGUAGE RecordWildCards #-} import Data.Foldable (for_) From 162895736c629ffd6cd082085d346164be098de8 Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Wed, 20 Sep 2017 12:47:53 -0300 Subject: [PATCH 4/8] Update config.json --- config.json | 1 - 1 file changed, 1 deletion(-) diff --git a/config.json b/config.json index 39fa3b4a1..dd2f6dbbc 100644 --- a/config.json +++ b/config.json @@ -75,7 +75,6 @@ "unlocked_by": null, "difficulty": 1, "topics": [ - "Data.Char" ] }, { From d1556eadc748688089e3261700ab9678f2caf245 Mon Sep 17 00:00:00 2001 From: Average-user Date: Thu, 21 Sep 2017 01:22:43 -0300 Subject: [PATCH 5/8] Test.hs correction --- exercises/isogram/test/Tests.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exercises/isogram/test/Tests.hs b/exercises/isogram/test/Tests.hs index a6811011c..50455734c 100644 --- a/exercises/isogram/test/Tests.hs +++ b/exercises/isogram/test/Tests.hs @@ -25,39 +25,39 @@ data Case = Case { description :: String cases :: [Case] cases = [ Case { description = "empty string" - , input = "" + , input = "" , expected = True } , Case { description = "isogram with only lower case characters" - , input = "isogram" + , input = "isogram" , expected = True } , Case { description = "word with one duplicated character" - , input = "eleven" + , input = "eleven" , expected = False } , Case { description = "longest reported english isogram" - , input = "subdermatoglyphic" + , input = "subdermatoglyphic" , expected = True } , Case { description = "word with duplicated character in mixed case" - , input = "Alphabet" + , input = "Alphabet" , expected = False } , Case { description = "hypothetical isogrammic word with hyphen" - , input = "thumbscrew-japingly" + , input = "thumbscrew-japingly" , expected = True } , Case { description = "isogram with duplicated non letter character" - , input = "Hjelmqvist-Gryb-Zock-Pfund-Wax" + , input = "Hjelmqvist-Gryb-Zock-Pfund-Wax" , expected = True } , Case { description = "made-up name that is an isogram" - , input = "Emily Jung Schwartzkopf" + , input = "Emily Jung Schwartzkopf" , expected = True } , Case { description = "duplicated character in the middle" - , input = "accentor" + , input = "accentor" , expected = False } ] From 17c7c2fa7857a4be4465ae0ebf2910d836d9bffa Mon Sep 17 00:00:00 2001 From: Lucas Polymeris Date: Thu, 21 Sep 2017 15:56:59 -0300 Subject: [PATCH 6/8] Update Isogram.hs --- exercises/isogram/src/Isogram.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/isogram/src/Isogram.hs b/exercises/isogram/src/Isogram.hs index 9da765bcf..9d5700607 100644 --- a/exercises/isogram/src/Isogram.hs +++ b/exercises/isogram/src/Isogram.hs @@ -1,5 +1,4 @@ module Isogram (isIsogram) where - isIsogram :: String -> Bool isIsogram = error "You need to implement this function!" From 47de49105718e943e7876b8bae4cbabd830b9ece Mon Sep 17 00:00:00 2001 From: Average-user Date: Thu, 21 Sep 2017 19:52:58 -0300 Subject: [PATCH 7/8] isogram, algorithm changed --- exercises/isogram/examples/success-standard/src/Isogram.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/exercises/isogram/examples/success-standard/src/Isogram.hs b/exercises/isogram/examples/success-standard/src/Isogram.hs index f7c8daea2..40cbaece5 100644 --- a/exercises/isogram/examples/success-standard/src/Isogram.hs +++ b/exercises/isogram/examples/success-standard/src/Isogram.hs @@ -1,8 +1,7 @@ module Isogram (isIsogram) where -import Data.Char (isLetter, toLower) +import Data.Char (toLower, isLetter) +import Data.List (sort, group) isIsogram :: String -> Bool -isIsogram = fn . map toLower - where fn [] = True - fn (x:xs) = not (isLetter x && x `elem` xs) && fn xs +isIsogram = all ((1==) . length) . group . sort . filter isLetter . map toLower From abf6d1ec643614ba72bf3f0c4850dc97101731fb Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Fri, 22 Sep 2017 21:00:34 -0700 Subject: [PATCH 8/8] isogram: regenerate readme --- exercises/isogram/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/exercises/isogram/README.md b/exercises/isogram/README.md index 29fb61c3e..49384d67e 100644 --- a/exercises/isogram/README.md +++ b/exercises/isogram/README.md @@ -6,10 +6,12 @@ An isogram (also known as a "nonpattern word") is a word or phrase without a rep Examples of isograms: -lumberjacks -background -downstream -The word isograms, however, is not an isogram, because the s repeats. +- lumberjacks +- background +- downstream + +The word *isograms*, however, is not an isogram, because the s repeats. + ## Getting Started @@ -65,8 +67,7 @@ one, head over there and create an issue. We'll do our best to help you! ## Source -see more at [wikipedia page of isograms]("https://en.wikipedia.org/wiki/Isogram") - +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.