Initial upload
This commit is contained in:
1
julia/scrabble-score/.exercism/metadata.json
Normal file
1
julia/scrabble-score/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"julia","exercise":"scrabble-score","id":"eb4d940ab0c344d19a57272dc9fe3da9","url":"https://exercism.io/my/solutions/eb4d940ab0c344d19a57272dc9fe3da9","handle":"halfdan","is_requester":true,"auto_approve":false}
|
50
julia/scrabble-score/README.md
Normal file
50
julia/scrabble-score/README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Scrabble Score
|
||||
|
||||
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.
|
||||
|
||||
## Source
|
||||
|
||||
Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)
|
||||
|
||||
## Version compatibility
|
||||
This exercise has been tested on Julia versions >=1.0.
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
51
julia/scrabble-score/runtests.jl
Normal file
51
julia/scrabble-score/runtests.jl
Normal file
@@ -0,0 +1,51 @@
|
||||
using Test
|
||||
|
||||
include("scrabble-score.jl")
|
||||
|
||||
@testset "lowercase letter" begin
|
||||
@test score("a") == 1
|
||||
end
|
||||
|
||||
@testset "uppercase letter" begin
|
||||
@test score("A") == 1
|
||||
end
|
||||
|
||||
@testset "valuable letter" begin
|
||||
@test score("f") == 4
|
||||
end
|
||||
|
||||
@testset "short word" begin
|
||||
@test score("at") == 2
|
||||
end
|
||||
|
||||
@testset "short, valuable word" begin
|
||||
@test score("zoo") == 12
|
||||
end
|
||||
|
||||
@testset "medium word" begin
|
||||
@test score("street") == 6
|
||||
end
|
||||
|
||||
@testset "medium, valuable word" begin
|
||||
@test score("quirky") == 22
|
||||
end
|
||||
|
||||
@testset "long, mixed-case word" begin
|
||||
@test score("OxyphenButazone") == 41
|
||||
end
|
||||
|
||||
@testset "english-like word" begin
|
||||
@test score("pinata") == 8
|
||||
end
|
||||
|
||||
@testset "non-english letter is not scored" begin
|
||||
@test score("piñata") == 7
|
||||
end
|
||||
|
||||
@testset "empty input" begin
|
||||
@test score("") == 0
|
||||
end
|
||||
|
||||
@testset "entire alphabet available" begin
|
||||
@test score("abcdefghijklmnopqrstuvwxyz") == 87
|
||||
end
|
68
julia/scrabble-score/scrabble-score.ipynb
Normal file
68
julia/scrabble-score/scrabble-score.ipynb
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": ["# Scrabble Score\n", "\n", "Given a word, compute the Scrabble score for that word.\n", "\n", "## Letter Values\n", "\n", "You'll need these:\n", "\n", "```text\n", "Letter Value\n", "A, E, I, O, U, L, N, R, S, T 1\n", "D, G 2\n", "B, C, M, P 3\n", "F, H, V, W, Y 4\n", "K 5\n", "J, X 8\n", "Q, Z 10\n", "```\n", "\n", "## Examples\n", "\n", "\"cabbage\" should be scored as worth 14 points:\n", "\n", "- 3 points for C\n", "- 1 point for A, twice\n", "- 3 points for B, twice\n", "- 2 points for G\n", "- 1 point for E\n", "\n", "And to total:\n", "\n", "- `3 + 2*1 + 2*3 + 2 + 1`\n", "- = `3 + 2 + 6 + 3`\n", "- = `5 + 9`\n", "- = 14\n", "\n", "## Extensions\n", "\n", "- You can play a double or a triple letter.\n", "- You can play a double or a triple word.\n", "\n", "## Source\n", "\n", "Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)\n", "\n", "## Version compatibility\n", "This exercise has been tested on Julia versions >=1.0.\n", "\n", "## Submitting Incomplete Solutions\n", "It's possible to submit an incomplete solution so you can see how others have completed the exercise."]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": ["## Your solution"]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": ["# submit\n", "function score(str)\n", "\n", "end"]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": ["## Test suite"]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": ["using Test\n", "\n", "# include(\"scrabble-score.jl\")\n", "\n", "@testset \"lowercase letter\" begin\n", " @test score(\"a\") == 1\n", "end\n", "\n", "@testset \"uppercase letter\" begin\n", " @test score(\"A\") == 1\n", "end\n", "\n", "@testset \"valuable letter\" begin\n", " @test score(\"f\") == 4\n", "end\n", "\n", "@testset \"short word\" begin\n", " @test score(\"at\") == 2\n", "end\n", "\n", "@testset \"short, valuable word\" begin\n", " @test score(\"zoo\") == 12\n", "end\n", "\n", "@testset \"medium word\" begin\n", " @test score(\"street\") == 6\n", "end\n", "\n", "@testset \"medium, valuable word\" begin\n", " @test score(\"quirky\") == 22\n", "end\n", "\n", "@testset \"long, mixed-case word\" begin\n", " @test score(\"OxyphenButazone\") == 41\n", "end\n", "\n", "@testset \"english-like word\" begin\n", " @test score(\"pinata\") == 8\n", "end\n", "\n", "@testset \"non-english letter is not scored\" begin\n", " @test score(\"piñata\") == 7\n", "end\n", "\n", "@testset \"empty input\" begin\n", " @test score(\"\") == 0\n", "end\n", "\n", "@testset \"entire alphabet available\" begin\n", " @test score(\"abcdefghijklmnopqrstuvwxyz\") == 87\n", "end"]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Prepare submission\n",
|
||||
"To submit your exercise, you need to save your solution in a file called `scrabble-score.jl` before using the CLI.\n",
|
||||
"You can either create it manually or use the following functions, which will automatically write every notebook cell that starts with `# submit` to the file `scrabble-score.jl`.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# using Pkg; Pkg.add(\"Exercism\")\n",
|
||||
"# using Exercism\n",
|
||||
"# Exercism.create_submission(\"scrabble-score\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Julia 1.3.0",
|
||||
"language": "julia",
|
||||
"name": "julia-1.3"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".jl",
|
||||
"mimetype": "application/julia",
|
||||
"name": "julia",
|
||||
"version": "1.3.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
36
julia/scrabble-score/scrabble-score.jl
Normal file
36
julia/scrabble-score/scrabble-score.jl
Normal file
@@ -0,0 +1,36 @@
|
||||
const CHARACTER_SCORES = Dict(
|
||||
'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
|
||||
)
|
||||
|
||||
function score(str::AbstractString)
|
||||
sum([score(uppercase(c)) for c in str])
|
||||
end
|
||||
|
||||
function score(c::Char)
|
||||
get(CHARACTER_SCORES, c, 0)
|
||||
end
|
Reference in New Issue
Block a user