-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding isogram #595
adding isogram #595
Changes from 2 commits
857bc67
ac9dd46
ebcd98e
1628957
d1556ea
17c7c2f
47de491
abf6d1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as you can see in https://github.com/Average-user/haskell/blob/d1556eadc748688089e3261700ab9678f2caf245/exercises/isogram/README.md, the quotes mean it is not a link. I'm going to regenerate this README anyway so it doesn't matter whether you fix this, but don't put quotes in the brackets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, so the next time i make PR like this, do i even have to put the README.md? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess not! I will just do it. However, it would be good if you just put a README.md that just says "please regenerate this for me" so that I don't forget to! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, also, dont merge yet, i want to implement something |
||
|
||
|
||
## Submitting Incomplete Solutions | ||
It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) = not (isLetter x && x `elem` xs) && fn xs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: isogram | ||
version: 1.1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Isogram (isIsogram) where | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove one newline here so there is only one between |
||
import Data.Char | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since
I would remove this line |
||
|
||
isIsogram :: String -> Bool | ||
isIsogram = error "You need to implement this function!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
resolver: lts-8.21 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given that #144 tells us this line helps for exercises with numbers but this is not one, I think it can be removed? |
||
{-# 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 | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in contrast to Maybe, I don't think this:
so I would remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right