Skip to content

Commit 190fe1b

Browse files
authored
add ETL (#197)
1 parent 1cb86a3 commit 190fe1b

File tree

10 files changed

+197
-0
lines changed

10 files changed

+197
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@
272272
"prerequisites": [],
273273
"difficulty": 2
274274
},
275+
{
276+
"slug": "etl",
277+
"name": "ETL",
278+
"uuid": "f3f3d1d9-5f1e-4bcf-8ae3-3f0de1019483",
279+
"practices": [],
280+
"prerequisites": [],
281+
"difficulty": 2
282+
},
275283
{
276284
"slug": "isogram",
277285
"name": "Isogram",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Instructions
2+
3+
Your task is to change the data format of letters and their point values in the game.
4+
5+
Currently, letters are stored in groups based on their score, in a one-to-many mapping.
6+
7+
- 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T",
8+
- 2 points: "D", "G",
9+
- 3 points: "B", "C", "M", "P",
10+
- 4 points: "F", "H", "V", "W", "Y",
11+
- 5 points: "K",
12+
- 8 points: "J", "X",
13+
- 10 points: "Q", "Z",
14+
15+
This needs to be changed to store each individual letter with its score in a one-to-one mapping.
16+
17+
- "a" is worth 1 point.
18+
- "b" is worth 3 points.
19+
- "c" is worth 3 points.
20+
- "d" is worth 2 points.
21+
- etc.
22+
23+
As part of this change, the team has also decided to change the letters to be lower-case rather than upper-case.
24+
25+
~~~~exercism/note
26+
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.
27+
~~~~
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
You work for a company that makes an online multiplayer game called Lexiconia.
4+
5+
To play the game, each player is given 13 letters, which they must rearrange to create words.
6+
Different letters have different point values, since it's easier to create words with some letters than others.
7+
8+
The game was originally launched in English, but it is very popular, and now the company wants to expand to other languages as well.
9+
10+
Different languages need to support different point values for letters.
11+
The point values are determined by how often letters are used, compared to other letters in that language.
12+
13+
For example, the letter 'C' is quite common in English, and is only worth 3 points.
14+
But in Norwegian it's a very rare letter, and is worth 10 points.
15+
16+
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.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"etl.wren"
8+
],
9+
"test": [
10+
"etl.spec.wren"
11+
],
12+
"example": [
13+
".meta/proof.ci.wren"
14+
]
15+
},
16+
"blurb": "Change the data format for scoring a game to more easily add other languages.",
17+
"source": "Based on an exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
18+
"source_url": "https://turing.edu"
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Etl {
2+
static toLowerUnsafe(str) {
3+
return str.codePoints.map(Fn.new { |cp| String.fromCodePoint(cp + 32) }).join()
4+
}
5+
6+
static transform(legacy) {
7+
var results = {}
8+
for (pair in legacy) {
9+
for (letter in pair.value) {
10+
var lowered = toLowerUnsafe(letter)
11+
results[lowered] = pair.key
12+
}
13+
}
14+
15+
return results
16+
}
17+
}
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[78a7a9f9-4490-4a47-8ee9-5a38bb47d28f]
13+
description = "single letter"
14+
15+
[60dbd000-451d-44c7-bdbb-97c73ac1f497]
16+
description = "single score with multiple letters"
17+
18+
[f5c5de0c-301f-4fdd-a0e5-df97d4214f54]
19+
description = "multiple scores with multiple letters"
20+
21+
[5db8ea89-ecb4-4dcd-902f-2b418cc87b9d]
22+
description = "multiple scores with differing numbers of letters"

exercises/practice/etl/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Exercism
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

exercises/practice/etl/etl.spec.wren

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import "./etl" for Etl
2+
import "wren-testie/testie" for Testie, Expect
3+
4+
Testie.test("ETL") { |do, skip|
5+
do.test("single letter") {
6+
var legacy = { 1: ["A"] }
7+
var actual = Etl.transform(legacy)
8+
var expected = { "a": 1 }
9+
Expect.value(actual).toEqual(expected)
10+
}
11+
12+
skip.test("single score with multiple letters") {
13+
var legacy = { 1: ["A", "E", "I", "O", "U"] }
14+
var actual = Etl.transform(legacy)
15+
var expected = { "a": 1, "e": 1, "i": 1, "o": 1, "u": 1 }
16+
Expect.value(actual).toEqual(expected)
17+
}
18+
19+
skip.test("multiple scores with multiple letters") {
20+
var legacy = { 1: ["A", "E"], 2: ["D", "G"] }
21+
var actual = Etl.transform(legacy)
22+
var expected = { "a": 1, "d": 2, "e": 1, "g": 2 }
23+
Expect.value(actual).toEqual(expected)
24+
}
25+
26+
skip.test("multiple scores with differing numbers of letters") {
27+
var legacy = {
28+
1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"],
29+
2: ["D", "G"],
30+
3: ["B", "C", "M", "P"],
31+
4: ["F", "H", "V", "W", "Y"],
32+
5: ["K"],
33+
8: ["J", "X"],
34+
10: ["Q", "Z"]
35+
}
36+
var actual = Etl.transform(legacy)
37+
var expected = {
38+
"a": 1, "b": 3, "c": 3, "d": 2, "e": 1, "f": 4, "g": 2, "h": 4,
39+
"i": 1, "j": 8, "k": 5, "l": 1, "m": 3, "n": 1, "o": 1, "p": 3,
40+
"q": 10, "r": 1, "s": 1, "t": 1, "u": 1, "v": 4, "w": 4, "x": 8,
41+
"y": 4, "z": 10
42+
}
43+
Expect.value(actual).toEqual(expected)
44+
}
45+
}
46+

exercises/practice/etl/etl.wren

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Etl {
2+
static transform(legacy) {
3+
Fiber.abort("Remove this statement and implement this function")
4+
}
5+
}
6+

exercises/practice/etl/package.wren

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import "wren-package" for WrenPackage, Dependency
2+
import "os" for Process
3+
4+
class Package is WrenPackage {
5+
construct new() {}
6+
name { "exercism/etl" }
7+
dependencies {
8+
return [
9+
Dependency.new("wren-testie", "0.3.0", "https://github.com/joshgoebel/wren-testie.git")
10+
]
11+
}
12+
}
13+
14+
Package.new().default()

0 commit comments

Comments
 (0)