mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-06 01:14:56 -06:00
add hello world properly, add rna-transcription (elixir is neat!)
This commit is contained in:
4
elixir/hello-world/.formatter.exs
Normal file
4
elixir/hello-world/.formatter.exs
Normal file
@@ -0,0 +1,4 @@
|
||||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
||||
24
elixir/hello-world/.gitignore
vendored
Normal file
24
elixir/hello-world/.gitignore
vendored
Normal file
@@ -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").
|
||||
hello_world-*.tar
|
||||
|
||||
9
elixir/hello-world/lib/hello_world.ex
Normal file
9
elixir/hello-world/lib/hello_world.ex
Normal file
@@ -0,0 +1,9 @@
|
||||
defmodule HelloWorld do
|
||||
@doc """
|
||||
Simply returns "Hello, World!"
|
||||
"""
|
||||
@spec hello :: String.t()
|
||||
def hello do
|
||||
"Hello, World!"
|
||||
end
|
||||
end
|
||||
28
elixir/hello-world/mix.exs
Normal file
28
elixir/hello-world/mix.exs
Normal file
@@ -0,0 +1,28 @@
|
||||
defmodule HelloWorld.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :hello_world,
|
||||
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
|
||||
7
elixir/hello-world/test/hello_world_test.exs
Normal file
7
elixir/hello-world/test/hello_world_test.exs
Normal file
@@ -0,0 +1,7 @@
|
||||
defmodule HelloWorldTest do
|
||||
use ExUnit.Case
|
||||
|
||||
test "says 'Hello, World!'" do
|
||||
assert HelloWorld.hello() == "Hello, World!"
|
||||
end
|
||||
end
|
||||
2
elixir/hello-world/test/test_helper.exs
Normal file
2
elixir/hello-world/test/test_helper.exs
Normal file
@@ -0,0 +1,2 @@
|
||||
ExUnit.start()
|
||||
ExUnit.configure(exclude: :pending, trace: true)
|
||||
1
elixir/rna-transcription/.exercism/metadata.json
Normal file
1
elixir/rna-transcription/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"elixir","exercise":"rna-transcription","id":"2c9f989893af4f9b81477a02cf3e2ce3","url":"https://exercism.io/my/solutions/2c9f989893af4f9b81477a02cf3e2ce3","handle":"Xevion","is_requester":true,"auto_approve":false}
|
||||
4
elixir/rna-transcription/.formatter.exs
Normal file
4
elixir/rna-transcription/.formatter.exs
Normal file
@@ -0,0 +1,4 @@
|
||||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
||||
24
elixir/rna-transcription/.gitignore
vendored
Normal file
24
elixir/rna-transcription/.gitignore
vendored
Normal file
@@ -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").
|
||||
rna_transcription-*.tar
|
||||
|
||||
61
elixir/rna-transcription/README.md
Normal file
61
elixir/rna-transcription/README.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# RNA Transcription
|
||||
|
||||
Given a DNA strand, return its RNA complement (per RNA transcription).
|
||||
|
||||
Both DNA and RNA strands are a sequence of nucleotides.
|
||||
|
||||
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**),
|
||||
guanine (**G**) and thymine (**T**).
|
||||
|
||||
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**),
|
||||
guanine (**G**) and uracil (**U**).
|
||||
|
||||
Given a DNA strand, its transcribed RNA strand is formed by replacing
|
||||
each nucleotide with its complement:
|
||||
|
||||
* `G` -> `C`
|
||||
* `C` -> `G`
|
||||
* `T` -> `A`
|
||||
* `A` -> `U`
|
||||
|
||||
## Running tests
|
||||
|
||||
Execute the tests with:
|
||||
|
||||
```bash
|
||||
$ mix test
|
||||
```
|
||||
|
||||
### Pending tests
|
||||
|
||||
In the test suites, all but the first test have been 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
|
||||
```
|
||||
|
||||
Or, you can enable all the tests by commenting out the
|
||||
`ExUnit.configure` line in the test suite.
|
||||
|
||||
```elixir
|
||||
# ExUnit.configure exclude: :pending, trace: true
|
||||
```
|
||||
|
||||
If you're stuck on something, it may help to look at some of
|
||||
the [available resources](https://exercism.io/tracks/elixir/resources)
|
||||
out there where answers might be found.
|
||||
|
||||
## Source
|
||||
|
||||
Hyperphysics [http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html](http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html)
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||
17
elixir/rna-transcription/lib/rna_transcription.ex
Normal file
17
elixir/rna-transcription/lib/rna_transcription.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule RnaTranscription do
|
||||
# Turns all 1-item charlist keys and values inside the base map into integers
|
||||
@transcription %{'G' => 'C', 'C' => 'G', 'T' => 'A', 'A' => 'U'} |> Enum.map(fn ({k, v}) -> {List.first(k), List.first(v)} end) |> Enum.into(%{})
|
||||
|
||||
@doc """
|
||||
Transcribes a character list representing DNA nucleotides to RNA
|
||||
|
||||
## Examples
|
||||
|
||||
iex> RnaTranscription.to_rna('ACTG')
|
||||
'UGAC'
|
||||
"""
|
||||
@spec to_rna([char]) :: [char]
|
||||
def to_rna(dna) do
|
||||
dna |> Enum.map(fn (x) -> Map.get(@transcription, x) end)
|
||||
end
|
||||
end
|
||||
28
elixir/rna-transcription/mix.exs
Normal file
28
elixir/rna-transcription/mix.exs
Normal file
@@ -0,0 +1,28 @@
|
||||
defmodule RnaTranscription.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :rna_transcription,
|
||||
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
|
||||
28
elixir/rna-transcription/test/rna_transcription_test.exs
Normal file
28
elixir/rna-transcription/test/rna_transcription_test.exs
Normal file
@@ -0,0 +1,28 @@
|
||||
defmodule RnaTranscriptionTest do
|
||||
use ExUnit.Case
|
||||
|
||||
@tag :pending
|
||||
test "transcribes guanine to cytosine" do
|
||||
assert RnaTranscription.to_rna('G') == 'C'
|
||||
end
|
||||
|
||||
@tag :pending
|
||||
test "transcribes cytosine to guanine" do
|
||||
assert RnaTranscription.to_rna('C') == 'G'
|
||||
end
|
||||
|
||||
@tag :pending
|
||||
test "transcribes thymidine to adenine" do
|
||||
assert RnaTranscription.to_rna('T') == 'A'
|
||||
end
|
||||
|
||||
@tag :pending
|
||||
test "transcribes adenine to uracil" do
|
||||
assert RnaTranscription.to_rna('A') == 'U'
|
||||
end
|
||||
|
||||
@tag :pending
|
||||
test "it transcribes all dna nucleotides to rna equivalents" do
|
||||
assert RnaTranscription.to_rna('ACGTGGTCTTAA') == 'UGCACCAGAAUU'
|
||||
end
|
||||
end
|
||||
2
elixir/rna-transcription/test/test_helper.exs
Normal file
2
elixir/rna-transcription/test/test_helper.exs
Normal file
@@ -0,0 +1,2 @@
|
||||
ExUnit.start()
|
||||
# ExUnit.configure(exclude: :pending, trace: true)
|
||||
Reference in New Issue
Block a user