Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add etl exercise (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored May 6, 2023
1 parent aed9b4c commit 10787e4
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@
"difficulty": 5,
"topics": null
},
{
"slug": "etl",
"name": "Etl",
"uuid": "c895c0f5-0fe5-4ce1-a3a9-b6cd911d9275",
"practices": [],
"prerequisites": [
"lists",
"numbers",
"strings"
],
"difficulty": 2
},
{
"slug": "difference-of-squares",
"name": "Difference Of Squares",
Expand Down
27 changes: 27 additions & 0 deletions exercises/practice/etl/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.
~~~~
16 changes: 16 additions & 0 deletions exercises/practice/etl/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.
19 changes: 19 additions & 0 deletions exercises/practice/etl/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"ErikSchierboom"
],
"files": {
"solution": [
"src/etl.cljs"
],
"test": [
"test/etl_test.cljs"
],
"example": [
".meta/src/example.cljs"
]
},
"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"
}
8 changes: 8 additions & 0 deletions exercises/practice/etl/.meta/src/example.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns etl
(:require [clojure.string :refer [lower-case]]))

(defn transform [extract]
(into {}
(for [[score letters] extract
letter letters]
[(lower-case letter) score])))
15 changes: 15 additions & 0 deletions exercises/practice/etl/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.

[78a7a9f9-4490-4a47-8ee9-5a38bb47d28f]
description = "single letter"

[60dbd000-451d-44c7-bdbb-97c73ac1f497]
description = "single score with multiple letters"

[f5c5de0c-301f-4fdd-a0e5-df97d4214f54]
description = "multiple scores with multiple letters"

[5db8ea89-ecb4-4dcd-902f-2b418cc87b9d]
description = "multiple scores with differing numbers of letters"
10 changes: 10 additions & 0 deletions exercises/practice/etl/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/clojurescript {:mvn/version "1.10.773"}}

:aliases
{:test
{:extra-paths ["test"]
:extra-deps
{olical/cljs-test-runner {:mvn/version "3.8.0"}}
:main-opts ["-m" "cljs-test-runner.main"]}}}
5 changes: 5 additions & 0 deletions exercises/practice/etl/src/etl.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns etl)

(defn transform [source] ;; <- arglist goes here
;; your code goes here
)
30 changes: 30 additions & 0 deletions exercises/practice/etl/test/etl_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns etl-test
(:require [clojure.test :refer [deftest is]]
etl))

(deftest transform-one-value
(is (= {"world" 1}
(etl/transform {1 ["WORLD"]}))))

(deftest transform-more-values
(is (= {"world" 1 "gschoolers" 1}
(etl/transform {1 ["WORLD" "GSCHOOLERS"]}))))

(deftest more-keys
(is (= {"apple" 1 "artichoke" 1 "boat" 2 "ballerina" 2}
(etl/transform {1 ["APPLE" "ARTICHOKE"], 2 ["BOAT" "BALLERINA"]}))))

(deftest full-dataset
(is (= {"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}
(etl/transform {1 (re-seq #"\w" "AEIOULNRST")
2 (re-seq #"\w" "DG")
3 (re-seq #"\w" "BCMP")
4 (re-seq #"\w" "FHVWY")
5 (re-seq #"\w" "K")
8 (re-seq #"\w" "JX")
10 (re-seq #"\w" "QZ")}))))

0 comments on commit 10787e4

Please sign in to comment.