mirror of
https://github.com/correl/elm.git
synced 2024-11-23 19:19:50 +00:00
commit
ab69147dd9
8 changed files with 227 additions and 0 deletions
10
config.json
10
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": [
|
||||
|
|
1
exercises/isogram/Isogram.elm
Normal file
1
exercises/isogram/Isogram.elm
Normal file
|
@ -0,0 +1 @@
|
|||
module Isogram exposing (..)
|
76
exercises/isogram/Isogram.example.elm
Normal file
76
exercises/isogram/Isogram.example.elm
Normal file
|
@ -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
|
50
exercises/isogram/README.md
Normal file
50
exercises/isogram/README.md
Normal file
|
@ -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.
|
14
exercises/isogram/elm-package.json
Normal file
14
exercises/isogram/elm-package.json
Normal file
|
@ -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"
|
||||
}
|
14
exercises/isogram/package.json
Normal file
14
exercises/isogram/package.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
46
exercises/isogram/tests/Tests.elm
Normal file
46
exercises/isogram/tests/Tests.elm
Normal file
|
@ -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"
|
||||
]
|
16
exercises/isogram/tests/elm-package.json
Normal file
16
exercises/isogram/tests/elm-package.json
Normal file
|
@ -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"
|
||||
}
|
Loading…
Reference in a new issue