[erlang-questions] omaha poker hand permutations
Torben Hoffmann
torben.lehoff@REDACTED
Tue Aug 16 20:32:23 CEST 2011
Hi Joel,
I wrote this one on the way home on the train:
1> Board = [a,b,c,d,e].
[a,b,c,d,e]
2> Hand = [1,2,3,4].
[1,2,3,4]
3> HandPairs = lists:usort( [lists:sort([A,B]) || A <- Hand, B <- Hand --
[A] ] ).
[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
4> BoardSets = lists:usort( [lists:sort([A,B,C]) || A <- Board, B <- (Board
-- [A]), C <- (Board -- [A,B]) ]).
[[a,b,c],
[a,b,d],
[a,b,e],
[a,c,d],
[a,c,e],
[a,d,e],
[b,c,d],
[b,c,e],
[b,d,e],
[c,d,e]]
5> Hands = [ HP ++ BS || HP <- HandPairs, BS <- BoardSets ].
[[1,2,a,b,c],
[1,2,a,b,d],
[1,2,a,b,e],
[1,2,a,c,d],
[1,2,a,c,e],
[1,2,a,d,e],
[1,2,b,c,d],
[1,2,b,c,e],
[1,2,b,d,e],
.....
It might not be the most efficient solution, but if you put it aside in a
function you can optimize it the day that it becomes the biggest bottleneck
in your system.
Cheers,
Torben
On Tue, Aug 16, 2011 at 18:26, Joel Reymont <joelr1@REDACTED> wrote:
> That works for me.
>
> Thank you folks!
>
> On Aug 16, 2011, at 3:38 PM, Marc Worrell wrote:
>
> > Can't you just do:
> >
> > L4 = [ {A, B} || A <- L3, B <- L3, A < B].
> >
> > This adds a strict ordering on the returned pairs.
>
> --------------------------------------------------------------------------
> - 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
>
--
http://www.linkedin.com/in/torbenhoffmann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110816/f6030657/attachment.htm>
More information about the erlang-questions
mailing list