Find the score of a scrabble word in haskell -
I have a letter mapped to my respective score
dict = fromList ( [("A", 1), ("B", 3), ("C", 3), ("E", 1), ("D", 2), ("G", 2) ("M", 3), ("f"), 4), ("i", 1), ("h", 4), ("k", 5) L "1"), ("O", 1), ("N", 1), ("Q", 10), ("P", 3), ("S", 1) , ("Y", 4), ("X", 8), ("U", 1), ("T", 1), ("W", 4) If a word is sent to the main function, then the function must return the score in terms of the words and words of the words. ("Jade", 10)]
EX: - Main: - should return the APLE function: - 9
(A score) 1+ (p score) 3 + (p score) 3 + (L Score) 1+ (E-Score) 1 = 9
main = Print $ calWordScore "APPLE" calculator: :: string - & gt; Int calcWordScore word = sum $ map calcLetterScore word calcLetterScore :: char - & gt; Int calcLetterScore ch = Map.fromList ([('A', 1), ('B', 3), ('C', 3), ('E', 1), ('D', 2) ' ',' 2 '), (' F ', 4), (' I ', 1),' 'H', 4 '' ('K', 5), '' J ', 8' , '3'), ('P', 3), ('L', 1), ('O', 1), ('N', 1), ('Q', 10) R ', 1), (' U ', 1), (' T ', 1), (' W ', 4), (' V ', 4), (' Y ', 4) , 8), ('Z', 10)] Maps.! Ch and the data you deserve. Map.Lazy must be imported as a map
Comments
Post a Comment