本文介绍了哈斯克尔对两张牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 目前我有卡片列表,现在我想在另一个列表中显示所有可能的卡片对。 例如: [(Card Club R2,Card Heart R3),(Card Club R2,Card Heart R4),(Card Club R2,Card Heart R5),(Card Club R2,Card心脏R6).........] 。 总结果可能是1326个不同的对 解决方案只要做 [(c1,c2)| c1 但这会返回2652对,如上所述。 为了将其复制到1326对,可以按照Zeta建议的方式或将 Ord 添加到卡: [(c1,c2)| c1< allCards,c2< allCards,c1< c2] Currently I have the Cards list,Now I want to show all the possible pairs of cards in another list.For example: [(Card Club R2, Card Heart R3), (Card Club R2, Card Heart R4), (Card Club R2, Card Heart R5), (Card Club R2, Card Heart R6).........]. The total result might be 1326 different pairs 解决方案 Just do[ (c1, c2) | c1 <- allCards, c2 <- allCards, c1 /= c2 ]But this will return 2652 pairs, as mentioned.To restict this to 1326 pairs, either do as Zeta suggested or add Ordto Card:[ (c1, c2) | c1 <- allCards, c2 <- allCards, c1 < c2 ] 这篇关于哈斯克尔对两张牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 18:11