-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,40 @@ | ||
# Instructions | ||
|
||
Given a word, compute the Scrabble score for that word. | ||
|
||
## Letter Values | ||
|
||
You'll need these: | ||
|
||
```text | ||
Letter Value | ||
A, E, I, O, U, L, N, R, S, T 1 | ||
D, G 2 | ||
B, C, M, P 3 | ||
F, H, V, W, Y 4 | ||
K 5 | ||
J, X 8 | ||
Q, Z 10 | ||
``` | ||
|
||
## Examples | ||
|
||
"cabbage" should be scored as worth 14 points: | ||
|
||
- 3 points for C | ||
- 1 point for A, twice | ||
- 3 points for B, twice | ||
- 2 points for G | ||
- 1 point for E | ||
|
||
And to total: | ||
|
||
- `3 + 2*1 + 2*3 + 2 + 1` | ||
- = `3 + 2 + 6 + 3` | ||
- = `5 + 9` | ||
- = 14 | ||
|
||
## Extensions | ||
|
||
- You can play a double or a triple letter. | ||
- You can play a double or a triple word. |
This file contains 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 @@ | ||
{ | ||
"authors": [ | ||
"BNAndras" | ||
], | ||
"files": { | ||
"solution": [ | ||
"scrabble_score.bal" | ||
], | ||
"test": [ | ||
"tests/scrabble_score_test.bal" | ||
], | ||
"example": [ | ||
".meta/reference/scrabble_score.bal" | ||
] | ||
}, | ||
"blurb": "Given a word, compute the Scrabble score for that word.", | ||
"source": "Inspired by the Extreme Startup game", | ||
"source_url": "https://github.com/rchatley/extreme_startup" | ||
} |
21 changes: 21 additions & 0 deletions
21
exercises/practice/scrabble-score/.meta/reference/scrabble_score.bal
This file contains 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,21 @@ | ||
# Calculate the points score for a word | ||
# | ||
# + word - the word to check | ||
# + return - the points score for the word | ||
function score(string word) returns int { | ||
int results = 0; | ||
foreach string c in word.toLowerAscii() { | ||
results += SCORES.get(c); | ||
} | ||
return results; | ||
} | ||
|
||
map<int> SCORES = { | ||
"a": 1, "e": 1, "i": 1, "o": 1, "u": 1, "l": 1, "n": 1, "r": 1, "s": 1, "t": 1, | ||
"d": 2, "g": 2, | ||
"b": 3, "c": 3, "m": 3, "p": 3, | ||
"f": 4, "h": 4, "v": 4, "w": 4, "y": 4, | ||
"k": 5, | ||
"j": 8, "x": 8, | ||
"q": 10, "z": 10 | ||
}; |
This file contains 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 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[f46cda29-1ca5-4ef2-bd45-388a767e3db2] | ||
description = "lowercase letter" | ||
|
||
[f7794b49-f13e-45d1-a933-4e48459b2201] | ||
description = "uppercase letter" | ||
|
||
[eaba9c76-f9fa-49c9-a1b0-d1ba3a5b31fa] | ||
description = "valuable letter" | ||
|
||
[f3c8c94e-bb48-4da2-b09f-e832e103151e] | ||
description = "short word" | ||
|
||
[71e3d8fa-900d-4548-930e-68e7067c4615] | ||
description = "short, valuable word" | ||
|
||
[d3088ad9-570c-4b51-8764-c75d5a430e99] | ||
description = "medium word" | ||
|
||
[fa20c572-ad86-400a-8511-64512daac352] | ||
description = "medium, valuable word" | ||
|
||
[9336f0ba-9c2b-4fa0-bd1c-2e2d328cf967] | ||
description = "long, mixed-case word" | ||
|
||
[1e34e2c3-e444-4ea7-b598-3c2b46fd2c10] | ||
description = "english-like word" | ||
|
||
[4efe3169-b3b6-4334-8bae-ff4ef24a7e4f] | ||
description = "empty input" | ||
|
||
[3b305c1c-f260-4e15-a5b5-cb7d3ea7c3d7] | ||
description = "entire alphabet available" |
This file contains 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,5 @@ | ||
[package] | ||
org = "anagy" | ||
name = "scrabble_score" | ||
version = "0.1.0" | ||
distribution = "2201.5.0" |
This file contains 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,38 @@ | ||
# AUTO-GENERATED FILE. DO NOT MODIFY. | ||
|
||
# This file is auto-generated by Ballerina for managing dependency versions. | ||
# It should not be modified by hand. | ||
|
||
[ballerina] | ||
dependencies-toml-version = "2" | ||
distribution-version = "2201.5.0" | ||
|
||
[[package]] | ||
org = "anagy" | ||
name = "scrabble_score" | ||
version = "0.1.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "test"} | ||
] | ||
modules = [ | ||
{org = "anagy", packageName = "scrabble_score", moduleName = "scrabble_score"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "jballerina.java" | ||
version = "0.0.0" | ||
scope = "testOnly" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "test" | ||
version = "0.0.0" | ||
scope = "testOnly" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "test", moduleName = "test"} | ||
] | ||
|
This file contains 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,7 @@ | ||
# Calculate the points score for a word | ||
# | ||
# + word - the word to check | ||
# + return - the points score for the word | ||
function score(string word) returns int { | ||
// TODO: implement this function | ||
} |
76 changes: 76 additions & 0 deletions
76
exercises/practice/scrabble-score/tests/scrabble_score_test.bal
This file contains 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,76 @@ | ||
import ballerina/test; | ||
|
||
@test:Config {} | ||
function testLowercaseLetter() { | ||
test:assertEquals(score("a"), 1); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testUppercaseLetter() { | ||
test:assertEquals(score("A"), 1); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testValuableLetter() { | ||
test:assertEquals(score("f"), 4); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testShortWord() { | ||
test:assertEquals(score("at"), 2); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testShortValuableWord() { | ||
test:assertEquals(score("zoo"), 12); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testMediumWord() { | ||
test:assertEquals(score("street"), 6); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testMediumValuableWord() { | ||
test:assertEquals(score("quirky"), 22); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testLongMixedCaseWord() { | ||
test:assertEquals(score("OxyphenButazone"), 41); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testEnglishLikeWord() { | ||
test:assertEquals(score("pinata"), 8); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testEmptyInput() { | ||
test:assertEquals(score(""), 0); | ||
} | ||
|
||
@test:Config { | ||
enable: false | ||
} | ||
function testEntireAlphabetAvailable() { | ||
test:assertEquals(score("abcdefghijklmnopqrstuvwxyz"), 87); | ||
} |