Skip to content

Project Euler Problem 54 – Harder than Expected.

February 26, 2010

Project Euler is a website that regularly posts computer programming puzzles – some easier than others.  I just solved problem 54 – although it took a LOT longer than I had hoped. Problem 54 takes a thousand games of poker between two players and determines how many times player 1 won.

I’ve posted the code I used here and here (WordPress is taking away my tabs – the original is more readable). The problem is not tricky and I don’t try any really fancy ways of solving them*. The reason I had problems with this one is because of typing. I had made two tables for comparisons – one had the suits of cards and the other had the face values in order. This gave me something to compare the cards to in various tests for the winner. However, I had set up the table to hold characters, my hands were composed of strings and I had forgotten to convert my hand values from strings to sets of characters in one of my tests.

I think if I rewrite it, I will pull the hand values and card suits apart up front and have them sent to the various tests instead of doing it within the sub tests. The latter makes more sense from an object-oriented point of view and allows me to, say, call the flush test from the straight test to check for a straight flush.

Anyways, I got it solved.  and am now moving on to Problem 76 🙂

Advertisements

From → Code

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: