diff --git a/config.json b/config.json index 69ce837..ef72fc3 100644 --- a/config.json +++ b/config.json @@ -11,6 +11,7 @@ "pangram", "accumulate", "triangle", + "scrabble-score", "anagram", "space-age", "strain", @@ -70,6 +71,11 @@ "difficulty": 1, "topics": [] }, + { + "slug": "scrabble-score", + "difficulty": 1, + "topics": [] + }, { "slug": "anagram", "difficulty": 1, diff --git a/elm-package.json b/elm-package.json index 2304e34..36eec37 100644 --- a/elm-package.json +++ b/elm-package.json @@ -17,6 +17,7 @@ "./exercises/anagram", "./exercises/raindrops", "./exercises/triangle", + "./exercises/scrabble-score", "./exercises/accumulate", "./exercises/sublist", "./exercises/sum-of-multiples", diff --git a/exercises/scrabble-score/ScrabbleScore.elm b/exercises/scrabble-score/ScrabbleScore.elm new file mode 100644 index 0000000..075ad46 --- /dev/null +++ b/exercises/scrabble-score/ScrabbleScore.elm @@ -0,0 +1 @@ +module ScrabbleScore exposing (..) diff --git a/exercises/scrabble-score/ScrabbleScore.example.elm b/exercises/scrabble-score/ScrabbleScore.example.elm new file mode 100644 index 0000000..7382d54 --- /dev/null +++ b/exercises/scrabble-score/ScrabbleScore.example.elm @@ -0,0 +1,32 @@ +module ScrabbleScore exposing (..) + +import String exposing (contains, foldl, fromChar, toUpper) + + +addLetterScore : Char -> Int -> Int +addLetterScore s total = + let + c = + toUpper (fromChar s) + in + if contains c "AEIOULNRST" then + total + 1 + else if contains c "DG" then + total + 2 + else if contains c "BCMP" then + total + 3 + else if contains c "FHVWY" then + total + 4 + else if contains c "K" then + total + 5 + else if contains c "JX" then + total + 8 + else if contains c "QZ" then + total + 10 + else + total + + +scoreWord : String -> Int +scoreWord x = + x |> foldl addLetterScore 0 diff --git a/exercises/scrabble-score/ScrabbleScoreTests.elm b/exercises/scrabble-score/ScrabbleScoreTests.elm new file mode 100644 index 0000000..66f5841 --- /dev/null +++ b/exercises/scrabble-score/ScrabbleScoreTests.elm @@ -0,0 +1,43 @@ +port module Main exposing (..) + +import Test.Runner.Node exposing (run) +import Json.Encode exposing (Value) +import Test exposing (..) +import Expect +import ScrabbleScore exposing (scoreWord) + + +tests : Test +tests = + describe "Grains" + [ test "lowercase letter" <| + \() -> Expect.equal 1 (scoreWord "a") + , test "uppercase letter" <| + \() -> Expect.equal 1 (scoreWord "A") + , test "valuable letter" <| + \() -> Expect.equal 4 (scoreWord "f") + , test "short word" <| + \() -> Expect.equal 2 (scoreWord "at") + , test "short, valuable word" <| + \() -> Expect.equal 12 (scoreWord "zoo") + , test "medium word" <| + \() -> Expect.equal 6 (scoreWord "street") + , test "medium, valuable word" <| + \() -> Expect.equal 22 (scoreWord "quirky") + , test "long, mixed-case word" <| + \() -> Expect.equal 41 (scoreWord "OxyphenButazone") + , test "english-like word" <| + \() -> Expect.equal 8 (scoreWord "pinata") + , test "non-english letter is not scored" <| + \() -> Expect.equal 7 (scoreWord "piƱata") + , test "empty input" <| + \() -> Expect.equal 0 (scoreWord "") + ] + + +main : Program Value +main = + run emit tests + + +port emit : ( String, Value ) -> Cmd msg diff --git a/exercises/scrabble-score/elm-package.json b/exercises/scrabble-score/elm-package.json new file mode 100644 index 0000000..82d2ab6 --- /dev/null +++ b/exercises/scrabble-score/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/xelm.git", + "license": "BSD3", + "source-directories": [ + "." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "4.0.0 <= v < 5.0.0", + "elm-community/elm-test": "2.0.0 <= v < 3.0.0", + "rtfeldman/node-test-runner": "2.0.0 <= v < 3.0.0" + }, + "elm-version": "0.17.0 <= v < 0.18.0" +} diff --git a/exercises/scrabble-score/runtests.bat b/exercises/scrabble-score/runtests.bat new file mode 100644 index 0000000..9ce824b --- /dev/null +++ b/exercises/scrabble-score/runtests.bat @@ -0,0 +1 @@ +ECHO We've changed how tests are run! Please review the latest install/running docs at http://exercism.io/languages/elm and report any issues at https://github.com/exercism/xelm diff --git a/exercises/scrabble-score/runtests.sh b/exercises/scrabble-score/runtests.sh new file mode 100644 index 0000000..6885122 --- /dev/null +++ b/exercises/scrabble-score/runtests.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo "We've changed how tests are run! Please review the latest install/running docs at http://exercism.io/languages/elm and report any issues at https://github.com/exercism/xelm"