[erlang-questions] omaha poker hand permutations

Richard O'Keefe <>
Wed Aug 17 06:34:23 CEST 2011


On 17/08/2011, at 2:27 AM, Joel Reymont wrote:

> The problem can be reduced to the following:
> 
> 5> L3 = ["AD", "AH", "AS", "QS"].
> ["AD","AH","AS","QS"]
> 
> 6> L4 = [ {A, B} || A <- L3, B <- L3, A /= B].                            
> [{"AD","AH"},
> {"AD","AS"},
> {"AD","QS"},
> {"AH","AD"},
> {"AH","AS"},
> {"AH","QS"},
> {"AS","AD"},
> {"AS","AH"},
> {"AS","QS"},
> {"QS","AD"},
> {"QS","AH"},
> {"QS","AS"}]
> 
> Note the duplicate pairs of AD, AH and AH, AD.
> 
> Can these be eliminated inside the list comprehension itself?

If you regard AD,AH and AH,AD as duplicates,
then presumably the order of {A, B} in the pairs does
not matter.

1> L3 = ["AD", "AH", "AS", "QH"].
["AD","AH","AS","QH"]
2> L4 = [{A, B} || A <- L3, B <- L3, A < B].
[{"AD","AH"},{"AD","AS"},{"AD","QH"},{"AH","AS"},{"AH","QH"},{"AS","QH"}]




More information about the erlang-questions mailing list