diff --git a/config.json b/config.json index 473d646..e8d0e16 100644 --- a/config.json +++ b/config.json @@ -352,6 +352,16 @@ "Lists", "Control-flow" ] + }, + { + "uuid": "5f540090-061e-2f80-40a8-d9782700ed2efdf8965", + "slug": "isogram", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "Lists" + ] } ], "foregone": [ diff --git a/exercises/isogram/Isogram.elm b/exercises/isogram/Isogram.elm new file mode 100644 index 0000000..984889c --- /dev/null +++ b/exercises/isogram/Isogram.elm @@ -0,0 +1 @@ +module Isogram exposing (..) diff --git a/exercises/isogram/Isogram.example.elm b/exercises/isogram/Isogram.example.elm new file mode 100644 index 0000000..7daa1bb --- /dev/null +++ b/exercises/isogram/Isogram.example.elm @@ -0,0 +1,76 @@ +module Isogram exposing (isIsogram) + +import String +import List +import Char + + +isLetter : Char -> Bool +isLetter c = + Char.isHexDigit c && (not <| Char.isDigit c) + + +isIsogram : String -> Bool +isIsogram sentence = + let + sanitized = + String.filter isLetter sentence + |> String.toLower + |> String.toList + |> List.sort + |> group + in + List.all (\x -> List.length x == 1) sanitized + + + +-- Adapted from https://github.com/elm-community/list-extra + + +group : List a -> List (List a) +group list = + case list of + [] -> + [] + + x :: xs -> + let + ( ys, zs ) = + span ((==) x) xs + in + (x :: ys) :: group zs + + +span : (a -> Bool) -> List a -> ( List a, List a ) +span p xs = + ( takeWhile p xs, dropWhile p xs ) + + +takeWhile : (a -> Bool) -> List a -> List a +takeWhile predicate = + let + takeWhileHelper acc list = + case list of + [] -> + List.reverse acc + + x :: xs -> + if (predicate x) then + takeWhileHelper (x :: acc) xs + else + List.reverse acc + in + takeWhileHelper [] + + +dropWhile : (a -> Bool) -> List a -> List a +dropWhile predicate list = + case list of + [] -> + [] + + x :: xs -> + if (predicate x) then + dropWhile predicate xs + else + list diff --git a/exercises/isogram/README.md b/exercises/isogram/README.md new file mode 100644 index 0000000..74818b6 --- /dev/null +++ b/exercises/isogram/README.md @@ -0,0 +1,50 @@ +# 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, however spaces and hyphens are allowed to appear multiple times. + +Examples of isograms: + +- lumberjacks +- background +- downstream +- six-year-old + +The word *isograms*, however, is not an isogram, because the s repeats. + +## Elm Installation + +Refer to the [Exercism help page](http://exercism.io/languages/elm) for Elm +installation and learning resources. + +## Writing the Code + +The first time you start an exercise, you'll need to ensure you have the +appropriate dependencies installed. + +```bash +$ npm install +``` + +Execute the tests with: + +```bash +$ npm test +``` + +Automatically run tests again when you save changes: + +```bash +$ npm run watch +``` + +As you work your way through the test suite, be sure to remove the `skip <|` +calls from each test until you get them all passing! + +## 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/elm-package.json b/exercises/isogram/elm-package.json new file mode 100644 index 0000000..132e19c --- /dev/null +++ b/exercises/isogram/elm-package.json @@ -0,0 +1,14 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/elm.git", + "license": "BSD3", + "source-directories": [ + "." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +} diff --git a/exercises/isogram/package.json b/exercises/isogram/package.json new file mode 100644 index 0000000..31d6fb3 --- /dev/null +++ b/exercises/isogram/package.json @@ -0,0 +1,14 @@ +{ + "description": "Exercism/Elm", + "repository": "https://github.com/exercism/elm.git", + "license": "MIT", + "scripts": { + "postinstall": "elm-package install -y", + "watch": "elm-test --watch", + "test": "elm-test" + }, + "dependencies": { + "elm": "0.18.0", + "elm-test": "0.18.3" + } +} diff --git a/exercises/isogram/tests/Tests.elm b/exercises/isogram/tests/Tests.elm new file mode 100644 index 0000000..503c6dd --- /dev/null +++ b/exercises/isogram/tests/Tests.elm @@ -0,0 +1,46 @@ +module Tests exposing (..) + +import Test exposing (..) +import Expect +import Isogram exposing (isIsogram) + + +tests : Test +tests = + describe "Isogram" + [ test "empty string" <| + \() -> + Expect.equal True <| isIsogram "" + , skip <| + test "isogram with only lower case characters" <| + \() -> + Expect.equal True <| isIsogram "isogram" + , skip <| + test "word with one duplicated character" <| + \() -> + Expect.equal False <| isIsogram "eleven" + , skip <| + test "longest reported english isogram" <| + \() -> + Expect.equal True <| isIsogram "subdermatoglyphic" + , skip <| + test "word with duplicated character in mixed case" <| + \() -> + Expect.equal False <| isIsogram "Alphabet" + , skip <| + test "hypothetical isogrammic word with hyphen" <| + \() -> + Expect.equal True <| isIsogram "thumbscrew-japingly" + , skip <| + test "isogram with duplicated non letter character" <| + \() -> + Expect.equal True <| isIsogram "Hjelmqvist-Gryb-Zock-Pfund-Wax" + , skip <| + test "made-up name that is an isogram" <| + \() -> + Expect.equal True <| isIsogram "Emily Jung Schwartzkopf" + , skip <| + test "duplicated character in the middle" <| + \() -> + Expect.equal False <| isIsogram "accentor" + ] diff --git a/exercises/isogram/tests/elm-package.json b/exercises/isogram/tests/elm-package.json new file mode 100644 index 0000000..3e92515 --- /dev/null +++ b/exercises/isogram/tests/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/elm.git", + "license": "BSD3", + "source-directories": [ + ".", + ".." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0", + "elm-community/elm-test": "4.0.0 <= v < 5.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +}