isogram
This commit is contained in:
parent
0c3373b87e
commit
379e523c04
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"jimmbraddock"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"angelikatyborska",
|
||||||
|
"awochna",
|
||||||
|
"Cohen-Carlisle",
|
||||||
|
"devonestes",
|
||||||
|
"lpil",
|
||||||
|
"neenjaw",
|
||||||
|
"parkerl",
|
||||||
|
"sotojuan"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"lib/isogram.ex"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"test/isogram_test.exs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.ex"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"blurb": "Determine if a word or phrase is an isogram.",
|
||||||
|
"source": "Wikipedia",
|
||||||
|
"source_url": "https://en.wikipedia.org/wiki/Isogram"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{"track":"elixir","exercise":"isogram","id":"97e0306c1cf5487e94c9f5a8a42aab63","url":"https://exercism.org/tracks/elixir/exercises/isogram","handle":"negrienko","is_requester":true,"auto_approve":false}
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Used by "mix format"
|
||||||
|
[
|
||||||
|
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||||
|
]
|
|
@ -0,0 +1,24 @@
|
||||||
|
# The directory Mix will write compiled artifacts to.
|
||||||
|
/_build/
|
||||||
|
|
||||||
|
# If you run "mix test --cover", coverage assets end up here.
|
||||||
|
/cover/
|
||||||
|
|
||||||
|
# The directory Mix downloads your dependencies sources to.
|
||||||
|
/deps/
|
||||||
|
|
||||||
|
# Where third-party dependencies like ExDoc output generated docs.
|
||||||
|
/doc/
|
||||||
|
|
||||||
|
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||||
|
/.fetch
|
||||||
|
|
||||||
|
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||||
|
erl_crash.dump
|
||||||
|
|
||||||
|
# Also ignore archive artifacts (built via "mix archive.build").
|
||||||
|
*.ez
|
||||||
|
|
||||||
|
# Ignore package tarball (built via "mix hex.build").
|
||||||
|
isogram-*.tar
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
From the terminal, change to the base directory of the exercise then execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mix test
|
||||||
|
```
|
||||||
|
|
||||||
|
This will execute the test file found in the `test` subfolder -- a file ending in `_test.exs`
|
||||||
|
|
||||||
|
Documentation:
|
||||||
|
|
||||||
|
* [`mix test` - Elixir's test execution tool](https://hexdocs.pm/mix/Mix.Tasks.Test.html)
|
||||||
|
* [`ExUnit` - Elixir's unit test library](https://hexdocs.pm/ex_unit/ExUnit.html)
|
||||||
|
|
||||||
|
## Pending tests
|
||||||
|
|
||||||
|
In test suites of practice exercises, all but the first test have been tagged to be skipped.
|
||||||
|
|
||||||
|
Once you get a test passing, you can unskip the next one by commenting out the relevant `@tag :pending` with a `#` symbol.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
# @tag :pending
|
||||||
|
test "shouting" do
|
||||||
|
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
If you wish to run all tests at once, you can include all skipped test by using the `--include` flag on the `mix test` command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mix test --include pending
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, you can enable all the tests by commenting out the `ExUnit.configure` line in the file `test/test_helper.exs`.
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
# ExUnit.configure(exclude: :pending, trace: true)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Useful `mix test` options
|
||||||
|
|
||||||
|
* `test/<FILE>.exs:LINENUM` - runs only a single test, the test from `<FILE>.exs` whose definition is on line `LINENUM`
|
||||||
|
* `--failed` - runs only tests that failed the last time they ran
|
||||||
|
* `--max-failures` - the suite stops evaluating tests when this number of test failures
|
||||||
|
is reached
|
||||||
|
* `--seed 0` - disables randomization so the tests in a single file will always be ran
|
||||||
|
in the same order they were defined in
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit lib/isogram.ex` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Elixir track's documentation](https://exercism.org/docs/tracks/elixir)
|
||||||
|
- The [Elixir track's programming category on the forum](https://forum.exercism.org/c/programming/elixir)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
If you're stuck on something, it may help to look at some of the [available resources](https://exercism.org/docs/tracks/elixir/resources) out there where answers might be found.
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Isogram
|
||||||
|
|
||||||
|
Welcome to Isogram on Exercism's Elixir Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Determine if a word or phrase is an isogram.
|
||||||
|
|
||||||
|
An isogram (also known as a "non-pattern 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.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @jimmbraddock
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @angelikatyborska
|
||||||
|
- @awochna
|
||||||
|
- @Cohen-Carlisle
|
||||||
|
- @devonestes
|
||||||
|
- @lpil
|
||||||
|
- @neenjaw
|
||||||
|
- @parkerl
|
||||||
|
- @sotojuan
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Wikipedia - https://en.wikipedia.org/wiki/Isogram
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Isogram do
|
||||||
|
@doc """
|
||||||
|
Determines if a word or sentence is an isogram
|
||||||
|
"""
|
||||||
|
@isogram ~r/(\w).*\1/i
|
||||||
|
|
||||||
|
@spec isogram?(String.t()) :: boolean
|
||||||
|
def isogram?(sentence), do: !Regex.match?(@isogram, String.downcase(sentence))
|
||||||
|
end
|
|
@ -0,0 +1,28 @@
|
||||||
|
defmodule Isogram.MixProject do
|
||||||
|
use Mix.Project
|
||||||
|
|
||||||
|
def project do
|
||||||
|
[
|
||||||
|
app: :isogram,
|
||||||
|
version: "0.1.0",
|
||||||
|
# elixir: "~> 1.8",
|
||||||
|
start_permanent: Mix.env() == :prod,
|
||||||
|
deps: deps()
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run "mix help compile.app" to learn about applications.
|
||||||
|
def application do
|
||||||
|
[
|
||||||
|
extra_applications: [:logger]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run "mix help deps" to learn about dependencies.
|
||||||
|
defp deps do
|
||||||
|
[
|
||||||
|
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||||
|
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,59 @@
|
||||||
|
defmodule IsogramTest do
|
||||||
|
use ExUnit.Case
|
||||||
|
|
||||||
|
test "empty string" do
|
||||||
|
assert Isogram.isogram?("")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "isogram with only lower case characters" do
|
||||||
|
assert Isogram.isogram?("isogram")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "word with one duplicated character" do
|
||||||
|
refute Isogram.isogram?("eleven")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "word with one duplicated character from the end of the alphabet" do
|
||||||
|
refute Isogram.isogram?("zzyzx")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "longest reported english isogram" do
|
||||||
|
assert Isogram.isogram?("subdermatoglyphic")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "word with duplicated character in mixed case" do
|
||||||
|
refute Isogram.isogram?("Alphabet")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "word with duplicated character in mixed case, lowercase first" do
|
||||||
|
refute Isogram.isogram?("alphAbet")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hypothetical isogrammic word with hyphen" do
|
||||||
|
assert Isogram.isogram?("thumbscrew-japingly")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hypothetical word with duplicated character following hyphen" do
|
||||||
|
refute Isogram.isogram?("thumbscrew-jappingly")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "isogram with duplicated hyphen" do
|
||||||
|
assert Isogram.isogram?("six-year-old")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "made-up name that is an isogram" do
|
||||||
|
assert Isogram.isogram?("Emily Jung Schwartzkopf")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "duplicated character in the middle" do
|
||||||
|
refute Isogram.isogram?("accentor")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "same first and last characters" do
|
||||||
|
refute Isogram.isogram?("angola")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "word with duplicated character and with two hyphens" do
|
||||||
|
refute Isogram.isogram?("up-to-date")
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
ExUnit.start()
|
||||||
|
ExUnit.configure(exclude: :pending, trace: true)
|
Loading…
Reference in New Issue