在haskell中找到拼字游戏单词的分数 [英] Find the score of a scrabble word in haskell

查看:128
本文介绍了在haskell中找到拼字游戏单词的分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字母映射其各自的分数

dict = fromList([(A,1),(B,3),(C,3), (E,1),(D,2),(G,2),(F,4),(I,1),(H,4),( K,5),(J,8),(M,3),(L,1),(O,1),(N,1),(Q ,10),(P,3),(S,1),(R,1),(U,1),(T,1),(W,4 ),(V,4),(Y,4),(X,8),(Z,10)])



如果主要向函数发送一个单词,该函数应该返回关于字典和单词中字母的分数。

EX: - 主要: - APPLE

功能应返回: - 9

(A分数)1+(P分数)3 +(P分数)3 +(L分数)1+(E分数)1 = 9

I am having a letter mapped with its respective score
dict = fromList([("A",1), ("B",3), ("C", 3), ("E", 1), ("D", 2), ("G", 2), ("F", 4), ("I", 1), ("H", 4), ("K", 5), ("J", 8), ("M", 3), ("L", 1), ("O", 1), ("N", 1), ("Q", 10), ("P", 3), ("S", 1), ("R", 1), ("U", 1), ("T", 1), ("W", 4), ("V", 4), ("Y", 4), ("X", 8), ("Z", 10)])

If the main send a word to the function the function should return the score with respect to the dict and the letters in the word.
EX:- Main :- APPLE
Function should return :- 9
(A Score)1+(P Score)3 +(P Score)3 + (L Score) 1+(E Score)1 = 9

推荐答案

一次读取一个字符的字符,找到您读入的字母的正确值(此时可能要强制为大写字母),并且总和值。
Read the characters of the word one character at a time, locate the correct value for the letter you read in (might want to force to upper case at this point), and sum the values.


这篇关于在haskell中找到拼字游戏单词的分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆