[erlang-questions] omaha poker hand permutations

Joel Reymont joelr1@REDACTED
Tue Aug 16 16:20:55 CEST 2011

Suppose I have a list of 5 common cards (Board) and another list of 4 private cards (#hand.cards).

I need to figure out all the possible poker hand rankings, but can only use 2 private cards and 3 common cards. 

What is the best way to compile a list of unique permutations here?

Following is a dumb approach that gives me 721 non-unique permutations but is there a better way?

	Thanks, Joel


omaha_collect_hands(_, [], Acc) ->

omaha_collect_hands(Board, [H|T], Acc) ->
    Hands = [ H#hand{ cards = [A, B, C, D, E] } || 
                A <- H#hand.cards,
                B <- H#hand.cards,
                A /= B,
                C <- Board,
                D <- Board,
                E <- Board,
                C /= D,
                C /= E,
                D /= E ],
    omaha_collect_hands(Board, T, prepend(Hands, Acc)).

prepend([], Target) 
  when is_list(Target) ->

prepend([H|Source], Target) 
  when is_list(Source),
       is_list(Target) ->
    prepend(Source, [H|Target]).
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont

More information about the erlang-questions mailing list