-
Notifications
You must be signed in to change notification settings - Fork 1
Morse decoder with Elixir #3
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
Merged
matiasbeckerle
merged 2 commits into
MakingSense:master
from
matiasbeckerle:morse-elixir
Mar 17, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Algorithms/Decode the morse code/Solutions/mbeckerle/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # 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 3rd-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 |
19 changes: 19 additions & 0 deletions
19
Algorithms/Decode the morse code/Solutions/mbeckerle/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Morse | ||
|
|
||
| Morse decoder library. | ||
|
|
||
| ## Installation | ||
|
|
||
| If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
| by adding `morse` to your list of dependencies in `mix.exs`: | ||
|
|
||
| ```elixir | ||
| def deps do | ||
| [{:morse, "~> 0.1.0"}] | ||
| end | ||
| ``` | ||
|
|
||
| Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
| and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
| be found at [https://hexdocs.pm/morse](https://hexdocs.pm/morse). | ||
|
|
||
30 changes: 30 additions & 0 deletions
30
Algorithms/Decode the morse code/Solutions/mbeckerle/config/config.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # This file is responsible for configuring your application | ||
| # and its dependencies with the aid of the Mix.Config module. | ||
| use Mix.Config | ||
|
|
||
| # This configuration is loaded before any dependency and is restricted | ||
| # to this project. If another project depends on this project, this | ||
| # file won't be loaded nor affect the parent project. For this reason, | ||
| # if you want to provide default values for your application for | ||
| # 3rd-party users, it should be done in your "mix.exs" file. | ||
|
|
||
| # You can configure for your application as: | ||
| # | ||
| # config :morse, key: :value | ||
| # | ||
| # And access this configuration in your application as: | ||
| # | ||
| # Application.get_env(:morse, :key) | ||
| # | ||
| # Or configure a 3rd-party app: | ||
| # | ||
| # config :logger, level: :info | ||
| # | ||
|
|
||
| # It is also possible to import configuration files, relative to this | ||
| # directory. For example, you can emulate configuration per environment | ||
| # by uncommenting the line below and defining dev.exs, test.exs and such. | ||
| # Configuration from the imported file will override the ones defined | ||
| # here (which is why it is important to import them last). | ||
| # | ||
| # import_config "#{Mix.env}.exs" |
25 changes: 25 additions & 0 deletions
25
Algorithms/Decode the morse code/Solutions/mbeckerle/lib/morse.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| defmodule Morse do | ||
| @moduledoc """ | ||
| Morse decoder library. | ||
| """ | ||
|
|
||
| @words_separator " " | ||
| @hacked_words_separator " @ " | ||
|
|
||
| @doc """ | ||
| Decode. | ||
|
|
||
| ## Examples | ||
|
|
||
| iex> Morse.decode ".... . .-.. .-.. ---" | ||
| "HELLO" | ||
|
|
||
| """ | ||
| def decode(morse_code) do | ||
| morse_code | ||
| |> String.replace(@words_separator, @hacked_words_separator) | ||
| |> String.split | ||
| |> Enum.map(fn x -> MorseDictionary.dictionary[x] end) | ||
| |> Enum.join | ||
| end | ||
| end |
43 changes: 43 additions & 0 deletions
43
Algorithms/Decode the morse code/Solutions/mbeckerle/lib/morse_dictionary.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| defmodule MorseDictionary do | ||
| @dictionary %{ | ||
| ".-" => "A", | ||
| "-..." => "B", | ||
| "-.-." => "C", | ||
| "-.." => "D", | ||
| "." => "E", | ||
| "..-." => "F", | ||
| "--." => "G", | ||
| "...." => "H", | ||
| ".." => "I", | ||
| ".---" => "J", | ||
| "-.-" => "K", | ||
| ".-.." => "L", | ||
| "--" => "M", | ||
| "-." => "N", | ||
| "---" => "O", | ||
| ".--." => "P", | ||
| "--.-" => "Q", | ||
| ".-." => "R", | ||
| "..." => "S", | ||
| "-" => "T", | ||
| "..-" => "U", | ||
| "...-" => "V", | ||
| ".--" => "W", | ||
| "-..-" => "X", | ||
| "-.--" => "Y", | ||
| "--.." => "Z", | ||
| "-----" => "0", | ||
| ".----" => "1", | ||
| "..---" => "2", | ||
| "...--" => "3", | ||
| "....-" => "4", | ||
| "....." => "5", | ||
| "-...." => "6", | ||
| "--..." => "7", | ||
| "---.." => "8", | ||
| "----." => "9", | ||
| "@" => " " | ||
| } | ||
|
|
||
| def dictionary, do: @dictionary | ||
| end |
33 changes: 33 additions & 0 deletions
33
Algorithms/Decode the morse code/Solutions/mbeckerle/mix.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| defmodule Morse.Mixfile do | ||
| use Mix.Project | ||
|
|
||
| def project do | ||
| [app: :morse, | ||
| version: "0.1.0", | ||
| elixir: "~> 1.4", | ||
| build_embedded: Mix.env == :prod, | ||
| start_permanent: Mix.env == :prod, | ||
| deps: deps()] | ||
| end | ||
|
|
||
| # Configuration for the OTP application | ||
| # | ||
| # Type "mix help compile.app" for more information | ||
| def application do | ||
| # Specify extra applications you'll use from Erlang/Elixir | ||
| [extra_applications: [:logger]] | ||
| end | ||
|
|
||
| # Dependencies can be Hex packages: | ||
| # | ||
| # {:my_dep, "~> 0.3.0"} | ||
| # | ||
| # Or git/path repositories: | ||
| # | ||
| # {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} | ||
| # | ||
| # Type "mix help deps" for more examples and options | ||
| defp deps do | ||
| [] | ||
| end | ||
| end |
8 changes: 8 additions & 0 deletions
8
Algorithms/Decode the morse code/Solutions/mbeckerle/test/morse_test.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| defmodule MorseTest do | ||
| use ExUnit.Case | ||
| doctest Morse | ||
|
|
||
| test "decode translates encoded messages" do | ||
| assert Morse.decode(".... . -.-- .--- ..- -.. .") == "HEY JUDE" | ||
| end | ||
| end |
1 change: 1 addition & 0 deletions
1
Algorithms/Decode the morse code/Solutions/mbeckerle/test/test_helper.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ExUnit.start() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Aw man, you DID publish them: https://hexdocs.pm/morse/Morse.html#content
That's so cool!
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.
Lol. That wasn't me 😄
But I definitively should clean up these docs. I'm probably to move this code to a personal repo and improve it.