#Scrabble
7 messages · Page 1 of 1 (latest)
please use code blocks when posting your code
please post code and error messsage so it is easier to replicate your issue
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.
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
Hi. I have checked the test cases. What failed were the test cases for 1) a single alphabet, and 2) no alphabets. I ran them locally, and got the correct results. Also, I added "filter isAlpha" to word before sending it to scrabble, so if there are no matches, it should return 0.
how did you run it locally? Did you run the tests or something else?
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