#Scrabble

7 messages · Page 1 of 1 (latest)

worthy vale
#

Hi. I am practicing Haskell, and there seems to be a problem with the "Scrabble" exercise. It works fine locally, but fails 2 test cases in Exercism. Also, the test are frequently getting timed out.
Could someone please let me know?

ivory token
#

please use code blocks when posting your code
please post code and error messsage so it is easier to replicate your issue

stoic parcel
#

For the first failing test, do you understand what’s being tested? You should be able to see the test cases in the Tests tab.

worthy vale
# ivory token please use code blocks when posting your code please post code and error messsag...

Sorry about that.

module Scrabble (scoreLetter, scoreWord) where
import Data.Maybe (fromMaybe)
import Data.Char ( toUpper,isAlpha)


-- scoreList = zip keys values
-- keys = ["AEIOULNRST","DG","BCMP","FHVWY","K","JX","QZ"]
-- values = [1,2,3,4,5,8,10]


scoreLetter :: Char -> Integer
scoreLetter letter = fromMaybe 0 $ lookup key1 scoreList
    where
        key1 = head [key | key <- keys, letter `elem` key]
        scoreList = zip keys values
        keys = ["AEIOULNRST","DG","BCMP","FHVWY","K","JX","QZ"]
        values = [1,2,3,4,5,8,10]


scoreWord :: String -> Integer
scoreWord word = sum $ map (scoreLetter . toUpper) $ filter isAlpha word


worthy vale
stoic parcel
#

how did you run it locally? Did you run the tests or something else?

worthy vale
#

Hi. Thank you everyone, for the help. In the test cases, there were 3 cases where the check was applied to characters. In the "scoreLetter" function. I had applied the check to only "scoreWord" function. Didn't look further after that. Well, I have modified the code after that. And it is working fine.


module Scrabble (scoreLetter, scoreWord) where
import Data.Maybe (fromMaybe)
import Data.Char ( toUpper,isAlpha)


scoreList = zip keys values
keys = ["AEIOULNRST","DG","BCMP","FHVWY","K","JX","QZ"]
values = [1,2,3,4,5,8,10]


scoreLetter :: Char -> Integer

scoreLetter letter =
    if not (isAlpha letter) then
        0
    else
        fromMaybe 0 $ lookup key1 scoreList
        where
            key1 = head [key | key <- keys, toUpper letter `elem` key]
        -- scoreList = zip keys values
        -- keys = ["AEIOULNRST","DG","BCMP","FHVWY","K","JX","QZ"]
        -- values = [1,2,3,4,5,8,10]


scoreWord :: String -> Integer
scoreWord word = sum $ map (scoreLetter . toUpper) $ filter isAlpha word