This commit is contained in:
Danil Negrienko 2024-06-26 23:30:11 -04:00
parent b62fcbc5ea
commit 10cfc2215b
10 changed files with 344 additions and 0 deletions

View File

@ -0,0 +1,40 @@
{
"authors": [
"rubysolo"
],
"contributors": [
"andrewsardone",
"angelikatyborska",
"bartj3",
"Cohen-Carlisle",
"dalexj",
"dantswain",
"devonestes",
"etrepum",
"henrik",
"herminiotorres",
"jinyeow",
"kytrinyx",
"lpil",
"neenjaw",
"parkerl",
"pminten",
"sotojuan",
"Teapane",
"waiting-for-dev"
],
"files": {
"solution": [
"lib/etl.ex"
],
"test": [
"test/etl_test.exs"
],
"example": [
".meta/example.ex"
]
},
"blurb": "Change the data format for scoring a game to more easily add other languages.",
"source": "Based on an exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
"source_url": "https://turing.edu"
}

View File

@ -0,0 +1 @@
{"track":"elixir","exercise":"etl","id":"92b4397f7b3f46c29ffc502cf111495f","url":"https://exercism.org/tracks/elixir/exercises/etl","handle":"negrienko","is_requester":true,"auto_approve":false}

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

24
elixir/etl/.gitignore vendored Normal file
View 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").
etl-*.tar

75
elixir/etl/HELP.md Normal file
View File

@ -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/etl.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.

81
elixir/etl/README.md Normal file
View File

@ -0,0 +1,81 @@
# ETL
Welcome to ETL on Exercism's Elixir Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Introduction
You work for a company that makes an online multiplayer game called Lexiconia.
To play the game, each player is given 13 letters, which they must rearrange to create words.
Different letters have different point values, since it's easier to create words with some letters than others.
The game was originally launched in English, but it is very popular, and now the company wants to expand to other languages as well.
Different languages need to support different point values for letters.
The point values are determined by how often letters are used, compared to other letters in that language.
For example, the letter 'C' is quite common in English, and is only worth 3 points.
But in Norwegian it's a very rare letter, and is worth 10 points.
To make it easier to add new languages, your team needs to change the way letters and their point values are stored in the game.
## Instructions
Your task is to change the data format of letters and their point values in the game.
Currently, letters are stored in groups based on their score, in a one-to-many mapping.
- 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T",
- 2 points: "D", "G",
- 3 points: "B", "C", "M", "P",
- 4 points: "F", "H", "V", "W", "Y",
- 5 points: "K",
- 8 points: "J", "X",
- 10 points: "Q", "Z",
This needs to be changed to store each individual letter with its score in a one-to-one mapping.
- "a" is worth 1 point.
- "b" is worth 3 points.
- "c" is worth 3 points.
- "d" is worth 2 points.
- etc.
As part of this change, the team has also decided to change the letters to be lower-case rather than upper-case.
~~~~exercism/note
If you want to look at how the data was previously structured and how it needs to change, take a look at the examples in the test suite.
~~~~
## Source
### Created by
- @rubysolo
### Contributed to by
- @andrewsardone
- @angelikatyborska
- @bartj3
- @Cohen-Carlisle
- @dalexj
- @dantswain
- @devonestes
- @etrepum
- @henrik
- @herminiotorres
- @jinyeow
- @kytrinyx
- @lpil
- @neenjaw
- @parkerl
- @pminten
- @sotojuan
- @Teapane
- @waiting-for-dev
### Based on
Based on an exercise by the JumpstartLab team for students at The Turing School of Software and Design. - https://turing.edu

16
elixir/etl/lib/etl.ex Normal file
View File

@ -0,0 +1,16 @@
defmodule ETL do
@doc """
Transforms an old Scrabble score system to a new one.
## Examples
iex> ETL.transform(%{1 => ["A", "E"], 2 => ["D", "G"]})
%{"a" => 1, "d" => 2, "e" => 1, "g" => 2}
"""
@spec transform(map) :: map
def transform(input) do
for {score, letters} <- input, letter <- letters, into: %{} do
{String.downcase(letter), score}
end
end
end

28
elixir/etl/mix.exs Normal file
View File

@ -0,0 +1,28 @@
defmodule Etl.MixProject do
use Mix.Project
def project do
[
app: :etl,
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

View File

@ -0,0 +1,73 @@
defmodule ETLTest do
use ExUnit.Case
test "single letter" do
old = %{1 => ["A"]}
expected = %{"a" => 1}
assert ETL.transform(old) == expected
end
test "single score with multiple letters" do
old = %{1 => ~W(A E I O U)}
expected = %{"a" => 1, "e" => 1, "i" => 1, "o" => 1, "u" => 1}
assert ETL.transform(old) == expected
end
test "multiple scores with multiple letters" do
old = %{1 => ["A", "E"], 2 => ["D", "G"]}
expected = %{
"a" => 1,
"d" => 2,
"e" => 1,
"g" => 2
}
assert ETL.transform(old) == expected
end
test "multiple scores with differing numbers of letters" do
old = %{
1 => ~W(A E I O U L N R S T),
2 => ~W(D G),
3 => ~W(B C M P),
4 => ~W(F H V W Y),
5 => ~W(K),
8 => ~W(J X),
10 => ~W(Q Z)
}
expected = %{
"a" => 1,
"b" => 3,
"c" => 3,
"d" => 2,
"e" => 1,
"f" => 4,
"g" => 2,
"h" => 4,
"i" => 1,
"j" => 8,
"k" => 5,
"l" => 1,
"m" => 3,
"n" => 1,
"o" => 1,
"p" => 3,
"q" => 10,
"r" => 1,
"s" => 1,
"t" => 1,
"u" => 1,
"v" => 4,
"w" => 4,
"x" => 8,
"y" => 4,
"z" => 10
}
assert ETL.transform(old) == expected
end
end

View File

@ -0,0 +1,2 @@
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)