Skip to content

Commit 82f36de

Browse files
authored
Add etl (#89)
1 parent 3f76369 commit 82f36de

File tree

10 files changed

+213
-0
lines changed

10 files changed

+213
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
"prerequisites": [],
9191
"difficulty": 2
9292
},
93+
{
94+
"slug": "etl",
95+
"name": "ETL",
96+
"uuid": "2c772f04-f65d-48f8-a19b-efaa84a5226d",
97+
"practices": [],
98+
"prerequisites": [],
99+
"difficulty": 2
100+
},
93101
{
94102
"slug": "hamming",
95103
"name": "Hamming",

exercises/practice/etl/.busted

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
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.moon"
8+
],
9+
"test": [
10+
"etl_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
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://www.turing.edu/"
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
transform: (legacy) ->
3+
result = {}
4+
for score, letters in pairs legacy
5+
for letter in *letters
6+
result[letter\lower!] = tonumber(score)
7+
result
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
string_list = (list) -> "{#{table.concat [quote(v) for v in *list], ', '}}"
2+
3+
{
4+
module_name: 'Etl',
5+
6+
generate_test: (case, level) ->
7+
lines = {}
8+
9+
table.insert lines, "legacy = {"
10+
for k, v in pairs case.input.legacy
11+
table.insert lines, " #{quote k}: #{string_list v}"
12+
table.insert lines, "}"
13+
14+
table.insert lines, "expected = {"
15+
for k, v in pairs case.expected
16+
table.insert lines, " #{quote k}: #{v}"
17+
table.insert lines, "}"
18+
19+
table.insert lines, "result = Etl.#{case.property} legacy"
20+
table.insert lines, "assert.are.same expected, result"
21+
22+
table.concat [indent line, level for line in *lines], '\n'
23+
}
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/etl.moon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
transform: (legacy) ->
3+
error 'Implement me!'
4+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Etl = require 'etl'
2+
3+
describe 'etl', ->
4+
it 'single letter', ->
5+
legacy = {
6+
'1': {'A'}
7+
}
8+
expected = {
9+
'a': 1
10+
}
11+
result = Etl.transform legacy
12+
assert.are.same expected, result
13+
14+
pending 'single score with multiple letters', ->
15+
legacy = {
16+
'1': {'A', 'E', 'I', 'O', 'U'}
17+
}
18+
expected = {
19+
'a': 1
20+
'e': 1
21+
'u': 1
22+
'o': 1
23+
'i': 1
24+
}
25+
result = Etl.transform legacy
26+
assert.are.same expected, result
27+
28+
pending 'multiple scores with multiple letters', ->
29+
legacy = {
30+
'1': {'A', 'E'}
31+
'2': {'D', 'G'}
32+
}
33+
expected = {
34+
'a': 1
35+
'd': 2
36+
'g': 2
37+
'e': 1
38+
}
39+
result = Etl.transform legacy
40+
assert.are.same expected, result
41+
42+
pending 'multiple scores with differing numbers of letters', ->
43+
legacy = {
44+
'1': {'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'}
45+
'8': {'J', 'X'}
46+
'3': {'B', 'C', 'M', 'P'}
47+
'2': {'D', 'G'}
48+
'5': {'K'}
49+
'4': {'F', 'H', 'V', 'W', 'Y'}
50+
'10': {'Q', 'Z'}
51+
}
52+
expected = {
53+
'a': 1
54+
'c': 3
55+
'b': 3
56+
'e': 1
57+
'd': 2
58+
'g': 2
59+
'f': 4
60+
'i': 1
61+
'h': 4
62+
'k': 5
63+
'j': 8
64+
'm': 3
65+
'l': 1
66+
'o': 1
67+
'n': 1
68+
'q': 10
69+
'p': 3
70+
's': 1
71+
'r': 1
72+
'u': 1
73+
't': 1
74+
'w': 4
75+
'v': 4
76+
'y': 4
77+
'x': 8
78+
'z': 10
79+
}
80+
result = Etl.transform legacy
81+
assert.are.same expected, result

0 commit comments

Comments
 (0)