mirror of
https://github.com/correl/elm.git
synced 2024-11-15 11:09:30 +00:00
add exercise scrabble-score
This commit is contained in:
parent
1197b527c3
commit
59571bc09a
8 changed files with 102 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"./exercises/anagram",
|
||||
"./exercises/raindrops",
|
||||
"./exercises/triangle",
|
||||
"./exercises/scrabble-score",
|
||||
"./exercises/accumulate",
|
||||
"./exercises/sublist",
|
||||
"./exercises/sum-of-multiples",
|
||||
|
|
1
exercises/scrabble-score/ScrabbleScore.elm
Normal file
1
exercises/scrabble-score/ScrabbleScore.elm
Normal file
|
@ -0,0 +1 @@
|
|||
module ScrabbleScore exposing (..)
|
32
exercises/scrabble-score/ScrabbleScore.example.elm
Normal file
32
exercises/scrabble-score/ScrabbleScore.example.elm
Normal file
|
@ -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
|
43
exercises/scrabble-score/ScrabbleScoreTests.elm
Normal file
43
exercises/scrabble-score/ScrabbleScoreTests.elm
Normal file
|
@ -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
|
16
exercises/scrabble-score/elm-package.json
Normal file
16
exercises/scrabble-score/elm-package.json
Normal file
|
@ -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"
|
||||
}
|
1
exercises/scrabble-score/runtests.bat
Normal file
1
exercises/scrabble-score/runtests.bat
Normal file
|
@ -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
|
2
exercises/scrabble-score/runtests.sh
Normal file
2
exercises/scrabble-score/runtests.sh
Normal file
|
@ -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"
|
Loading…
Reference in a new issue