# [erlang-questions] omaha poker hand permutations

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue Aug 16 17:07:09 CEST 2011

```On Tue, Aug 16, 2011 at 03:27:43PM +0100, Joel Reymont wrote:
> The problem can be reduced to the following:
>
> 5> L3 = ["AD", "AH", "AS", "QS"].
>
> 6> L4 = [ {A, B} || A <- L3, B <- L3, A /= B].
>  {"AH","AS"},
>  {"AH","QS"},
>  {"AS","AH"},
>  {"AS","QS"},
>  {"QS","AH"},
>  {"QS","AS"}]
>
>
> Can these be eliminated inside the list comprehension itself?

I guess no, since list comprehension permutation assumes order is
Comparisions can only be done between generated term components.

In this case you better write it with functions, the outer chewing off one
combining with the rest. Remember that list comprehensions are just
high level list function notation.

For example:
perm([A|[_|_]=As]) -> perm(A, lists:reverse(As), perm(As));
perm([_|_]) -> [];
perm([]) -> [].

perm(A, [B|Bs], Acc) -> perm(A, Bs, [{A,B}|Acc]);
perm(_, [], Acc) -> Acc.

{"AH","QS"},
{"AH","AS"},
{"AS","QS"}]

>
> 	Thanks, Joel
>
> --------------------------------------------------------------------------
> - for hire: mac osx device driver ninja, kernel extensions and usb drivers
> ---------------------+------------+---------------------------------------
> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
> ---------------------+------------+---------------------------------------
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB

```