This blog has moved to Medium

Subscribe via email

Posts tagged ‘Poker’

## Most annoying Euler problem yet

In Problem 54, you receive a set of poker hands, and are asked to count the number of times Player 1 won. No algorithmic or mathematical intelligence here, just coding. I advise skipping it in favor of more interesting problems.

Some say the Chinese word for “crisis” is composed of “danger” and opportunity (others do not). I took the time to play with LINQ and lambdas for the first time (in C# at least), and it was a great deal of fun – even at my home computer which is currently suffering from lack of Resharper.

SPOILER SPOILER SPOILER

Here’s a bit of LINQ goodness. The method I used (SPOILER SPOILER) to calculate the winner of two similar hands is a weighted sum. I summed all the best cards with a high weight, then added less important cards with lower weight (for example, 3 twos get more weight each than 2 kings in the same hand).

Once I found which value is the best in a given hand (2 in the above hand), I used this little one liner to count the number of cards equal to the maximal value.

`_cards.Where(c => c.Value == bestValue).Count();`

## Poker Night

After playing some poker one on one versus Aya on the train today, we played some Texas Holdem tonight. Since we’re not playing for money, I keep an imaginary balance of my wins/losses. If I pay 10 imaginary dollars per game, I’m currently at -30\$ total 🙁

Shimi and Aya won the Holdem games, and it was, as poker nights are usuelly, as very funny night. My personal favorite activity during poker games is trying to guess other players’ cards, telling them what I think they have, and advising (commanding 🙂 them on how to proceed. For some reason, it seems to convince the other players I actually know what I’m talking about. If I did, I wouldn’t be at a -30\$ balance, wouldn’t I?