Compare commits
No commits in common. "95c9a93dec3e47bdd2967065831d7470e66710d5" and "5f594b12e34253c0e676be3fd74a9e703ad79975" have entirely different histories.
95c9a93dec
...
5f594b12e3
@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"authors": [
|
|
||||||
"petehuang"
|
|
||||||
],
|
|
||||||
"contributors": [
|
|
||||||
"andrewsardone",
|
|
||||||
"angelikatyborska",
|
|
||||||
"Cohen-Carlisle",
|
|
||||||
"dalexj",
|
|
||||||
"devonestes",
|
|
||||||
"jinyeow",
|
|
||||||
"kytrinyx",
|
|
||||||
"lpil",
|
|
||||||
"neenjaw",
|
|
||||||
"parkerl",
|
|
||||||
"rubysolo",
|
|
||||||
"Scientifica96",
|
|
||||||
"sotojuan",
|
|
||||||
"Teapane",
|
|
||||||
"waiting-for-dev"
|
|
||||||
],
|
|
||||||
"files": {
|
|
||||||
"solution": [
|
|
||||||
"lib/squares.ex"
|
|
||||||
],
|
|
||||||
"test": [
|
|
||||||
"test/squares_test.exs"
|
|
||||||
],
|
|
||||||
"example": [
|
|
||||||
".meta/example.ex"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.",
|
|
||||||
"source": "Problem 6 at Project Euler",
|
|
||||||
"source_url": "https://projecteuler.net/problem=6"
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
{"track":"elixir","exercise":"difference-of-squares","id":"71804265a0684ed3ba15a88ed184ef81","url":"https://exercism.org/tracks/elixir/exercises/difference-of-squares","handle":"negrienko","is_requester":true,"auto_approve":false}
|
|
@ -1,4 +0,0 @@
|
|||||||
# Used by "mix format"
|
|
||||||
[
|
|
||||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
|
||||||
]
|
|
24
elixir/difference-of-squares/.gitignore
vendored
24
elixir/difference-of-squares/.gitignore
vendored
@ -1,24 +0,0 @@
|
|||||||
# 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").
|
|
||||||
difference_of_squares-*.tar
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
|||||||
# 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/squares.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.
|
|
@ -1,47 +0,0 @@
|
|||||||
# Difference of Squares
|
|
||||||
|
|
||||||
Welcome to Difference of Squares on Exercism's Elixir Track.
|
|
||||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
|
|
||||||
Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.
|
|
||||||
|
|
||||||
The square of the sum of the first ten natural numbers is
|
|
||||||
(1 + 2 + ... + 10)² = 55² = 3025.
|
|
||||||
|
|
||||||
The sum of the squares of the first ten natural numbers is
|
|
||||||
1² + 2² + ... + 10² = 385.
|
|
||||||
|
|
||||||
Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is 3025 - 385 = 2640.
|
|
||||||
|
|
||||||
You are not expected to discover an efficient solution to this yourself from first principles; research is allowed, indeed, encouraged.
|
|
||||||
Finding the best algorithm for the problem is a key skill in software engineering.
|
|
||||||
|
|
||||||
## Source
|
|
||||||
|
|
||||||
### Created by
|
|
||||||
|
|
||||||
- @petehuang
|
|
||||||
|
|
||||||
### Contributed to by
|
|
||||||
|
|
||||||
- @andrewsardone
|
|
||||||
- @angelikatyborska
|
|
||||||
- @Cohen-Carlisle
|
|
||||||
- @dalexj
|
|
||||||
- @devonestes
|
|
||||||
- @jinyeow
|
|
||||||
- @kytrinyx
|
|
||||||
- @lpil
|
|
||||||
- @neenjaw
|
|
||||||
- @parkerl
|
|
||||||
- @rubysolo
|
|
||||||
- @Scientifica96
|
|
||||||
- @sotojuan
|
|
||||||
- @Teapane
|
|
||||||
- @waiting-for-dev
|
|
||||||
|
|
||||||
### Based on
|
|
||||||
|
|
||||||
Problem 6 at Project Euler - https://projecteuler.net/problem=6
|
|
@ -1,29 +0,0 @@
|
|||||||
defmodule Squares do
|
|
||||||
@moduledoc """
|
|
||||||
Calculate sum of squares, square of sum, difference between two sums from 1 to a given end number.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Calculate sum of squares from 1 to a given end number.
|
|
||||||
"""
|
|
||||||
@spec sum_of_squares(pos_integer) :: pos_integer
|
|
||||||
def sum_of_squares(number) do
|
|
||||||
div(number * (number + 1) * (2 * number + 1), 6)
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Calculate square of sum from 1 to a given end number.
|
|
||||||
"""
|
|
||||||
@spec square_of_sum(pos_integer) :: pos_integer
|
|
||||||
def square_of_sum(number) do
|
|
||||||
div(number * (number + 1), 2) ** 2
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Calculate difference between sum of squares and square of sum from 1 to a given end number.
|
|
||||||
"""
|
|
||||||
@spec difference(pos_integer) :: pos_integer
|
|
||||||
def difference(number) do
|
|
||||||
abs(square_of_sum(number) - sum_of_squares(number))
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,29 +0,0 @@
|
|||||||
defmodule Squares.MixProject do
|
|
||||||
use Mix.Project
|
|
||||||
|
|
||||||
def project do
|
|
||||||
[
|
|
||||||
app: :squares,
|
|
||||||
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
|
|
||||||
[
|
|
||||||
{:lettuce, "~> 0.3.0", only: ~w(dev)a}
|
|
||||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
|
||||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,3 +0,0 @@
|
|||||||
%{
|
|
||||||
"lettuce": {:hex, :lettuce, "0.3.0", "823198f053714282f980acc68c7157b9c78c740910cb4f572a642e020417a850", [:mix], [], "hexpm", "a47479d94ac37460481133213f08c8283dabbe762f4f8f8028456500d1fca9c4"},
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
defmodule SquaresTest do
|
|
||||||
use ExUnit.Case
|
|
||||||
|
|
||||||
describe "square_of_sum" do
|
|
||||||
test "square of sum to 1" do
|
|
||||||
assert Squares.square_of_sum(1) == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
test "square of sum to 5" do
|
|
||||||
assert Squares.square_of_sum(5) == 225
|
|
||||||
end
|
|
||||||
|
|
||||||
test "square of sum to 100" do
|
|
||||||
assert Squares.square_of_sum(100) == 25_502_500
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "sum_of_squares" do
|
|
||||||
test "sum of squares to 1" do
|
|
||||||
assert Squares.sum_of_squares(1) == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
test "sum of squares to 5" do
|
|
||||||
assert Squares.sum_of_squares(5) == 55
|
|
||||||
end
|
|
||||||
|
|
||||||
test "sum of squares to 100" do
|
|
||||||
assert Squares.sum_of_squares(100) == 338_350
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "difference" do
|
|
||||||
test "difference of sum to 1" do
|
|
||||||
assert Squares.difference(1) == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
test "difference of sum to 5" do
|
|
||||||
assert Squares.difference(5) == 170
|
|
||||||
end
|
|
||||||
|
|
||||||
test "difference of sum to 100" do
|
|
||||||
assert Squares.difference(100) == 25_164_150
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,2 +0,0 @@
|
|||||||
ExUnit.start()
|
|
||||||
ExUnit.configure(exclude: :pending, trace: true)
|
|
@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"authors": [
|
|
||||||
"Tuxified"
|
|
||||||
],
|
|
||||||
"contributors": [
|
|
||||||
"angelikatyborska",
|
|
||||||
"Cohen-Carlisle",
|
|
||||||
"devonestes",
|
|
||||||
"neenjaw",
|
|
||||||
"sotojuan"
|
|
||||||
],
|
|
||||||
"files": {
|
|
||||||
"solution": [
|
|
||||||
"lib/dominoes.ex"
|
|
||||||
],
|
|
||||||
"test": [
|
|
||||||
"test/dominoes_test.exs"
|
|
||||||
],
|
|
||||||
"example": [
|
|
||||||
".meta/example.ex"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"blurb": "Make a chain of dominoes."
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
{"track":"elixir","exercise":"dominoes","id":"c3029f8eea4743b88999e49c85863daa","url":"https://exercism.org/tracks/elixir/exercises/dominoes","handle":"negrienko","is_requester":true,"auto_approve":false}
|
|
@ -1,4 +0,0 @@
|
|||||||
# Used by "mix format"
|
|
||||||
[
|
|
||||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
|
||||||
]
|
|
24
elixir/dominoes/.gitignore
vendored
24
elixir/dominoes/.gitignore
vendored
@ -1,24 +0,0 @@
|
|||||||
# 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").
|
|
||||||
dominoes-*.tar
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
|||||||
# 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/dominoes.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.
|
|
@ -1,48 +0,0 @@
|
|||||||
# Dominoes
|
|
||||||
|
|
||||||
Welcome to Dominoes on Exercism's Elixir Track.
|
|
||||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
|
|
||||||
In Toyland, the trains are always busy delivering treasures across the city, from shiny marbles to rare building blocks.
|
|
||||||
The tracks they run on are made of colorful domino-shaped pieces, each marked with two numbers.
|
|
||||||
For the trains to move, the dominoes must form a perfect chain where the numbers match.
|
|
||||||
|
|
||||||
Today, an urgent delivery of rare toys is on hold.
|
|
||||||
You've been handed a set of track pieces to inspect.
|
|
||||||
If they can form a continuous chain, the train will be on its way, bringing smiles across Toyland.
|
|
||||||
If not, the set will be discarded, and another will be tried.
|
|
||||||
|
|
||||||
The toys are counting on you to solve this puzzle.
|
|
||||||
Will the dominoes connect the tracks and send the train rolling, or will the set be left behind?
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
|
|
||||||
Make a chain of dominoes.
|
|
||||||
|
|
||||||
Compute a way to order a given set of domino stones so that they form a correct domino chain.
|
|
||||||
In the chain, the dots on one half of a stone must match the dots on the neighboring half of an adjacent stone.
|
|
||||||
Additionally, the dots on the halves of the stones without neighbors (the first and last stone) must match each other.
|
|
||||||
|
|
||||||
For example given the stones `[2|1]`, `[2|3]` and `[1|3]` you should compute something
|
|
||||||
like `[1|2] [2|3] [3|1]` or `[3|2] [2|1] [1|3]` or `[1|3] [3|2] [2|1]` etc, where the first and last numbers are the same.
|
|
||||||
|
|
||||||
For stones `[1|2]`, `[4|1]` and `[2|3]` the resulting chain is not valid: `[4|1] [1|2] [2|3]`'s first and last numbers are not the same.
|
|
||||||
4 != 3
|
|
||||||
|
|
||||||
Some test cases may use duplicate stones in a chain solution, assume that multiple Domino sets are being used.
|
|
||||||
|
|
||||||
## Source
|
|
||||||
|
|
||||||
### Created by
|
|
||||||
|
|
||||||
- @Tuxified
|
|
||||||
|
|
||||||
### Contributed to by
|
|
||||||
|
|
||||||
- @angelikatyborska
|
|
||||||
- @Cohen-Carlisle
|
|
||||||
- @devonestes
|
|
||||||
- @neenjaw
|
|
||||||
- @sotojuan
|
|
@ -1,22 +0,0 @@
|
|||||||
defmodule Dominoes do
|
|
||||||
@type domino :: {1..6, 1..6}
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
chain?/1 takes a list of domino stones and returns boolean indicating if it's
|
|
||||||
possible to make a full chain
|
|
||||||
"""
|
|
||||||
@spec chain?(dominoes :: [domino]) :: boolean
|
|
||||||
def chain?([]), do: true
|
|
||||||
def chain?([{first, second}]) when first == second, do: true
|
|
||||||
|
|
||||||
def chain?([{first, second} | dominoes]) do
|
|
||||||
Enum.any?(
|
|
||||||
dominoes,
|
|
||||||
fn
|
|
||||||
{^first, x} = domino -> chain?([{second, x} | List.delete(dominoes, domino)])
|
|
||||||
{x, ^first} = domino -> chain?([{second, x} | List.delete(dominoes, domino)])
|
|
||||||
_ -> false
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,29 +0,0 @@
|
|||||||
defmodule Dominoes.MixProject do
|
|
||||||
use Mix.Project
|
|
||||||
|
|
||||||
def project do
|
|
||||||
[
|
|
||||||
app: :dominoes,
|
|
||||||
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
|
|
||||||
[
|
|
||||||
{:lettuce, "~> 0.3.0", only: ~w(dev)a}
|
|
||||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
|
||||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,74 +0,0 @@
|
|||||||
defmodule DominoesTest do
|
|
||||||
use ExUnit.Case
|
|
||||||
|
|
||||||
test "empty input = empty output" do
|
|
||||||
assert Dominoes.chain?([]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "singleton input = singleton output" do
|
|
||||||
assert Dominoes.chain?([{1, 1}]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "singleton that can't be chained" do
|
|
||||||
assert Dominoes.chain?([{1, 2}]) == false
|
|
||||||
end
|
|
||||||
|
|
||||||
test "three elements" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {3, 1}, {2, 3}]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "can reverse dominoes" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {1, 3}, {2, 3}]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "can't be chained" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {4, 1}, {2, 3}]) == false
|
|
||||||
end
|
|
||||||
|
|
||||||
test "disconnected - double loop" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {2, 1}, {3, 4}, {4, 3}]) == false
|
|
||||||
end
|
|
||||||
|
|
||||||
test "disconnected - single isolated" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {4, 4}]) == false
|
|
||||||
end
|
|
||||||
|
|
||||||
test "need backtrack" do
|
|
||||||
# a variation in which we have to turn but no duplicates
|
|
||||||
assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {2, 4}, {2, 4}]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "separate loops" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {1, 1}, {2, 2}, {3, 3}]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "nine elements" do
|
|
||||||
assert Dominoes.chain?([
|
|
||||||
{1, 2},
|
|
||||||
{5, 3},
|
|
||||||
{3, 1},
|
|
||||||
{1, 2},
|
|
||||||
{2, 4},
|
|
||||||
{1, 6},
|
|
||||||
{2, 3},
|
|
||||||
{3, 4},
|
|
||||||
{5, 6}
|
|
||||||
]) == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "separate three-domino loops" do
|
|
||||||
refute Dominoes.chain?([{1, 2}, {2, 3}, {3, 1}, {4, 5}, {5, 6}, {6, 4}])
|
|
||||||
end
|
|
||||||
|
|
||||||
test "disconnected - simple" do
|
|
||||||
refute Dominoes.chain?([{1, 1}, {2, 2}])
|
|
||||||
end
|
|
||||||
|
|
||||||
test "first and last not matching" do
|
|
||||||
assert Dominoes.chain?([{1, 2}, {2, 3}, {3, 4}]) == false
|
|
||||||
end
|
|
||||||
|
|
||||||
test "wrong starting order" do
|
|
||||||
assert Dominoes.chain?([{2, 1}, {2, 3}, {3, 1}]) == true
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,2 +0,0 @@
|
|||||||
ExUnit.start()
|
|
||||||
ExUnit.configure(exclude: :pending, trace: true)
|
|
Loading…
x
Reference in New Issue
Block a user